Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Applications > iTunes AppleScript Question

iTunes AppleScript Question
Thread Tools
Fresh-Faced Recruit
Join Date: Dec 2007
Status: Offline
Reply With Quote
Jan 3, 2008, 04:36 PM
 
Here's the scoop. Now that iTunes supports multiple libraries I have my complete iTunes library on an external HD (containing all movies, tv shows, music, etc) and a smaller one on my MacBook (containing favorite shows and CDs). I wanted iTunes to automatically choose the complete library on the External drive if it was available and default to the internal drive if it wasn't. Basically, I don't want to hold option and navigate to the library manually. In addition I thought it would be cool to preserve the original functionality of holding option to manually select a library in the instances where I wanted some manual control.

I was able to do this with the AppleScript below. I made copies of com.apple.iTunes.plist for the external HD and the internal one and moved them to their own folders in ~/Library/Preferences (the folders are iTunes Local and iTunes Complete). On running, the script checks to see if option is pressed, if it is iTunes is launched. If not, it checks to see whether the external library exsits, if it does it swaps in the Complete preferences file (which places the library on the external HD). If it does not exist it swaps in the Local preferences file.

Now my problem. The script works great if I click 'Run' in Script Editor. But if I save it as an application and run it, the preferences files copy but iTunes never launches, holding down option or not. Why isn't iTunes launching? Am I missing something trivial?

Thanks in advance!

Oh, I hope people find this script useful (if it gets working, that is)!

[codex]if "keys pressed" contains "Option" then
tell application "iTunes"
activate
end tell
else
tell application "Finder"
if (exists "Ben:Volumes:Ben's External Drive:iTunes Complete:iTunes Library") then
duplicate file "Ben:Users:ben:Library:Preferences:iTunes Complete:com.apple.iTunes.plist" to folder "Ben:Users:ben:Library:Preferences" with replacing
else
duplicate file "Ben:Users:ben:Library:Preferences:iTunes Local:com.apple.iTunes.plist" to folder "Ben:Users:ben:Library:Preferences" with replacing
end if

end tell
tell application "iTunes"
activate
end tell
end if[/codex]
     
Fresh-Faced Recruit
Join Date: Dec 2007
Status: Offline
Reply With Quote
Jan 4, 2008, 11:38 AM
 
Ok, I solved my own problem. Its a bad idea to name the script iTunes and save it as an application, because then it doesn't know which iTunes to activate. Oops!

Anyways, here is the full script I'm using now, it works like a charm! It calls extra suites which can be found here:Kanzu | Software.

[codex]tell application "Extra Suites" to set kd to ES keys down
if kd contains "Option" then
display dialog "Please Choose a Library" buttons {"Local", "External"}
if button returned of result = "Local" then
tell application "Finder"
duplicate file "Ben:Users:ben:Library:Preferences:iTunes Local:com.apple.iTunes.plist" to folder "Ben:Users:ben:Library:Preferences" with replacing
end tell
tell application "iTunes" to activate
else
tell application "Finder"
if (exists "Ben:Volumes:Ben's External Drive:iTunes Complete:iTunes Library") then
duplicate file "Ben:Users:ben:Library:Preferences:iTunes Complete:com.apple.iTunes.plist" to folder "Ben:Users:ben:Library:Preferences" with replacing
tell application "iTunes" to activate
else
display dialog "External hard drive not connected" buttons {"OK"} default button "OK"
end if
end tell
end if
else
tell application "Finder"
if (exists "Ben:Volumes:Ben's External Drive:iTunes Complete:iTunes Library") then
duplicate file "Ben:Users:ben:Library:Preferences:iTunes Complete:com.apple.iTunes.plist" to folder "Ben:Users:ben:Library:Preferences" with replacing
else
duplicate file "Ben:Users:ben:Library:Preferences:iTunes Local:com.apple.iTunes.plist" to folder "Ben:Users:ben:Library:Preferences" with replacing
end if
stop
end tell
tell application "iTunes" to activate
end if[/codex]
(Last edited by notyourtypical; Jan 4, 2008 at 11:42 AM. (Reason:Forgot to disable smilies))
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:48 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2