and I'm all out of bubble gum…

I just mentioned that my wife switches between two different iTunes libraries, including one that lives on a shared volume on our home server. There’s a great tip on Stack Overflow for writing a script to automate that swap between iTunes libraries (rather than having to hold down option while iTunes loads and then click around to find the library you want). But it seemed like it might be nice to document for posterity the full script that we’ve built, since it handles not just the library swapping, but also the mounting of the shared volume as well.

This script takes a little prep work, both generating the library location property and storing the authentication information in the user keychain. The Stack Overflow tip explains the former, and the latter is as easy as connecting to the server and remembering to check the “Save Authentication” checkbox during the authentication process.

-- set server connection information here
property serverProtocol : "afp://"
property serverName : "your-server-name-here.local"
property volumeName : "shared-volume-name-here"
-- define the desired library location and save the current library location ( explains exactly how to generate the appalling hexadecimal value for iTunesLibraryLocation below)
property iTunesLibraryLocation : ""
property libraryLocationPref : " 'alis:1:iTunes Library Location'"
-- try to mount share from server
	-- authentication credentials stored in keychain
	mount volume (serverProtocol & serverName & "/" & volumeName)
on error
	-- if we can't mount the share, we're done
	display dialog "The shared volume “" & volumeName & "” on the server “" & serverName & "” could not be mounted, so the remote iTunes Library cannot be used. Please check that you are on the same network as “Leviathan” and try again later." buttons ("Le sigh") default button 1 giving up after 15
end try
-- quit iTunes if it's running
tell application "System Events"
	if exists (application process "iTunes") then
		tell application "iTunes" to quit
	end if
end tell
-- set the desired library location
do shell script "defaults write " & libraryLocationPref & " " & quoted form of iTunesLibraryLocation
-- comment the above shell script and uncomment the one below to use the default iTunes Library
-- do shell script "defaults delete " & libraryLocationPref
-- (re)open iTunes
tell application "iTunes" to activate

March 18th, 2014

Posted In: How To

Tags: , ,

A bit of background: my wife has an iTunes library that is too large to fit comfortably on her MacBook Air (in all fairness: I have an iTunes library that is too large to fit on her MacBook Air, my MacBook Pro and several other laptops as well). She maintains a local library on her laptop for use at school (useful movies, songs, etc.) and stores her “real” library on our home server. Which involves a bit of fiddling to get it to work. The key issue is that she needs iTunes to load her library off of a shared disk. And, periodically (maybe every couple of months), something goes haywire and she gets this error:

The iTunes library Library file is locked, on a locked disk, or you do not have write permission for this file.

Needless to say, this is exasperating.

There are a number of suggested solutions out there, and I keep forgetting to bookmark “the one” that works. On my last search, I realized that this was because none of them are really the answer that works in our situation. Here’s what works (and I’m posting this as a note for self):

  1. Disconnect the laptop from the server (quitting iTunes first, of course).
  2. On the server, unset the nouchg flag (not 100% that this is necessary 100% of the time, but it’s necessary at least some of the time):
    sudo chflags -R nouchg <path to iTunes folder>
  3. Reboot the server.
  4. Reconnect from the laptop and rejoice.

At least, that’s what worked this evening, and it felt really familiar. (There’s an unspoken step 2a, of course: cancel the multi-hour process on the server that you had queued up moments before iTunes started misbehaving. Argh.)

March 18th, 2014

Posted In: How To

Tags: , , ,