Skip to content

Instantly share code, notes, and snippets.

@battis
Last active August 21, 2018 13:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save battis/966e6314355a147d5e78096d09a29394 to your computer and use it in GitHub Desktop.
Save battis/966e6314355a147d5e78096d09a29394 to your computer and use it in GitHub Desktop.
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