Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Toggling between iTunes Libraries
41 16 * * * syncPodcasts
17 2 * * * open $HOME/Library/iTunes/Scripts/Libraries/Open\ Music\ \&\ Audiobooks\ Library.app
43 2 * * * open $HOME/Library/iTunes/Scripts/Libraries/Open\ Movies\ \&\ TV\ Shows\ Library.app
run script "/Volumes/Home/seth/Library/iTunes/Scripts/Libraries/Toggle iTunes Library.app" with parameters {"/Volumes/Home/seth/Music/iTunes (Movies & TV Shows)"}
tell application "iTunes" to reveal playlist named "Movies"
run script "/Volumes/Home/seth/Library/iTunes/Scripts/Libraries/Toggle iTunes Library.app" with parameters {"/Volumes/Home/seth/Music/iTunes (Music & Audiobooks)"}
property libraryPaths : {¬
"/Volumes/Home/seth/Music/iTunes (Music & Audiobooks)", ¬
"/Volumes/Home/seth/Music/iTunes (Movies & TV Shows)"}
property currentLibrary : 1
on run (thePath)
quitIfRunning()
clearCustomLibraryLocation()
if class of thePath is not list then
rotateLibrary()
openLibraryAt(item currentLibrary of libraryPaths)
else
setCurrentLibraryTo(thePath)
openLibraryAt(thePath)
end if
end run
on clearCustomLibraryLocation()
try
do shell script "defaults delete com.apple.itunes 'alis:1:iTunes Library Location'"
on error
-- do nothing
end try
end clearCustomLibraryLocation
on quitIfRunning()
tell application "System Events"
get name of every process whose name is "iTunes"
if result is not {} then
tell application "iTunes"
quit
end tell
set stillQuitting to true
repeat while stillQuitting is true
get name of every process whose name is "iTunes"
if result is not {} then
delay 1
else
set stillQuitting to false
end if
end repeat
end if
end tell
end quitIfRunning
on openLibraryAt(thePath as text)
do shell script "rm $HOME/Music/iTunes; ln -s \"" & thePath & "\" $HOME/Music/iTunes"
tell application "iTunes" to activate
end openLibraryAt
on setCurrentLibraryTo(thePath)
repeat with n from 1 to count of libraryPaths
if thePath is item n of libraryPaths then
set currentLibrary to n
end if
end repeat
end setCurrentLibraryTo
on rotateLibrary()
set currentLibrary to (currentLibrary + 1) mod ((count of libraryPaths) + 1)
if currentLibrary is 0 then
set currentLibrary to 1
end if
end rotateLibrary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment