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\
43 2 * * * open $HOME/Library/iTunes/Scripts/Libraries/Open\ Movies\ \&\ TV\ Shows\
run script "/Volumes/Home/seth/Library/iTunes/Scripts/Libraries/Toggle iTunes" 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" 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)
if class of thePath is not list then
openLibraryAt(item currentLibrary of libraryPaths)
end if
end run
on clearCustomLibraryLocation()
do shell script "defaults delete '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"
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
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