Hi folks,
is it possible to change the iTunes library with AppleScript? I’m using the context sensitive Application ControlPlane and would like to change the iTunes library according to my enviroment.
Regards,
Tristan
Hi folks,
is it possible to change the iTunes library with AppleScript? I’m using the context sensitive Application ControlPlane and would like to change the iTunes library according to my enviroment.
Regards,
Tristan
Using Smile additions:
property itunesprefs : alias "Leopard:Users:otto:Library:Preferences:com.apple.iTunes.plist"
property ituneslib : "alis:1:iTunes Library Location"
on swap(nextlib)
set prf to PlistOpen itunesprefs
PlistSet prf key ituneslib to nextlib without typed -- as «data» ?
PlistSave prf
PlistClose prf
end swap
on getiTunesFolder()
set prf to PlistOpen itunesprefs
set x to PlistGet prf key ituneslib as alias
PlistClose prf
return x
end getiTunesFolder
It might be possible to convert this to use System Events property lists.
It’s not wise to put full paths into properties: they may or may not work on other machines. This will work anywhere, anytime:
set itunesprefs to (((path to preferences from user domain) as text) & "com.apple.iTunes.plist") as alias
In iTunes 10.6 I do not see ‘alis:1:iTunes Library Location’: instead, I have ‘WebKitLocalStorageDatabasePathPreferenceKey’. It contains the path to folder “iTunes”, not “iTunes/Music”. You can access this key easily with defaults:
-- to read:
set itunesFolderLocation to do shell script "defaults read com.apple.itunes WebKitLocalStorageDatabasePathPreferenceKey"
-- to write:
set itunesFolderLocation to do shell script "defaults write com.apple.itunes WebKitLocalStorageDatabasePathPreferenceKey"
No, it’s not wise. As it is, it’s guaranteed to not work anywhere else.
Writing there is probably useless to make iTunes change library. It would be nice though, as it is a string.
I don’t know to which versions ‘alis:1:iTunes Library Location’ applies, it works for 1 year or so of consecutive versions: 10.*
A google search turned up this…
http://stackoverflow.com/questions/1693780/applescript-to-launch-itunes-with-a-specific-library
That explains why Alastor cannot see it in his library!