Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Switch between two iTunes Libraries' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Switch between two iTunes Libraries
Authored by: martyl on Nov 28, '05 09:14:54PM

Is there any way for you to post that script? Sounds like it's just what I'm looking for...

Thanks!!

---
Marty Lindower



[ Reply to This | # ]
Switch between two iTunes Libraries
Authored by: Dephex Twin on Nov 29, '05 05:05:16PM

Here it is, I couldn't do the indenting, but if you copied this into AppleScript it would of course indent it for you:


(*

The only thing extra you need to set up for this is creating two folders in the Music folder of your client computer. (Actually you can put these folders anywhere on the client but in my code it is the Music folder.) The folders are named "iTunes Data Local" and "iTunes Data Server" in my code. Take the two library files ("iTunes 4 Music Library" and "iTunes Music Library.xml") that you currently have in the client iTunes folder and put them in the "iTunes Data Local" folder. Now mount the server and go to the equivalent place on the server where its two library files are. Make aliases to those files and put those aliases on your client where the originals were.

The program will be swapping the original client settings and the aliases to the server ones, and that is basically how it works.

It should be obvious which parts you need to customize but if not then let me know.

*)


try

do shell script "top -l1 | grep -w iTunes"

--Check to see if iTunes is already running on the laptop, in which case do nothing.

on error

tell application "Finder"

set useServer to true

try

set localFolder to folder "iTunes" of folder "Music" of home

end try

try

set serverFolder to folder "iTunes" of folder "Music" of disk "Server HD"

--Try to make a reference to the server hard drive

on error

--Making the reference failed, and that means the laptop is not connected to the server yet.

display dialog "Not connected to music server. Connect?" buttons {"Use Local", "OK"} default button "OK"

if button returned of the result is not equal to "OK" then

set useServer to false

else

try

mount volume "afp://yourlogin@yourserver.local/server_harddrive_name"

--this mounts the server drive, I don't put in the password here for security reasons, but you can put it in like this:

-- afp://yourlogin:password@yourserver.local/server_harddrive_name

on error

display dialog "Could not connect to server."

quit

end try

end if

end try

if useServer then

-- Depending on what is being used, local or server

set folderBeingUsed to (folder "iTunes Data Server" of folder "Music" of home)

set otherFolder to (folder "iTunes Data Local" of folder "Music" of home)

else

set otherFolder to (folder "iTunes Data Server" of folder "Music" of home)

set folderBeingUsed to (folder "iTunes Data Local" of folder "Music" of home)

end if

if (count of items of folderBeingUsed) is less than 1 then

try

--If the folder I am getting settings from is empty, that means the settings are already in the right place, so just run the program

open application "iTunes"

end try

else

--This swaps the settings that are currently there with the other ones.

set theFiles to {file "iTunes 4 Music Library" of folder "iTunes" of folder "Music" of home, file "iTunes Music Library.xml" of folder "iTunes" of folder "Music" of home}

move theFiles to otherFolder

set theFiles to {file "iTunes 4 Music Library" of folderBeingUsed, file "iTunes Music Library.xml" of folderBeingUsed}

move theFiles to folder "iTunes" of folder "Music" of home

try

open application "iTunes"

end try

end if

end tell

end try

end if

---
"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"

[ Reply to This | # ]

Switch between two iTunes Libraries
Authored by: Dephex Twin on Nov 29, '05 05:08:47PM

Oh, and if you wanted this to just work for an external drive instead of on a network, you could just cut out everything after "on error" up to before the second "end try", and insert the line "set useServer to false"

---
"Knicks suck, Yankees suck, Mets suck..."
"...Krypton sucks"



[ Reply to This | # ]
Two bugs in your script...
Authored by: phow4rd on Dec 02, '05 04:46:48PM

#1: There's an extra "end if" at the end.

#2: Every instance of "iTunes 4 Music Library" should be changed to "iTunes Library" (assuming you're not using iTunes 4.x).

I haven't finished testing it yet, and I want to integrate the choice of using an external drive, so I'll post more later.



[ Reply to This | # ]