Skip to content

Instantly share code, notes, and snippets.

@battis
Last active July 31, 2017 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/f5c56faaaf05b32918debc79bb443c3a to your computer and use it in GitHub Desktop.
Save battis/f5c56faaaf05b32918debc79bb443c3a to your computer and use it in GitHub Desktop.
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