change itunes library

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.



Using Smile additions:

property itunesprefs : alias ""
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) & "") 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 WebKitLocalStorageDatabasePathPreferenceKey"
-- to write:
set itunesFolderLocation to do shell script "defaults write 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…

That explains why Alastor cannot see it in his library!