Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Reliably Open iTunes Library on a Shared Volume
-- 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 (http://stackoverflow.com/a/1693973/294171 explains exactly how to generate the appalling hexadecimal value for iTunesLibraryLocation below)
property iTunesLibraryLocation : ""
property libraryLocationPref : "com.apple.iTunes 'alis:1:iTunes Library Location'"
-- try to mount share from server
try
-- 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
return
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment