Script won't run as Application

Hey, I have a question for the gurus!

I wrote the following script for the purpose of automatically checking to see if my external HD was present and automatically using that iTunes library. Basically it checks to see if option is held down, if it is it launches iTunes without changing preferences, and if you continue holding option you can manually select which library to use (useful for manual changes). Without option, it checks to see if the external library is present, than copies the preference file associated with that library and launches iTunes. If the drive is not present, it loads the local library. This script works without a hitch when I click ‘Run’ from within Script Editor, but when I save it as an application and try using it, it doesn’t work. Any ideas why?

Thanks in advance!

tell application "Extra Suites" to set kd to ES keys down
if kd 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

Also, is there anything other than Extra Suites that will get a key press? I hear Jon’s is PPC only, so its a no go.

Model: MacBook 3,1
AppleScript: 2.0
Browser: Safari 523.10.6
Operating System: Mac OS X (10.5)

Why not enclose the whole thing in a try block with the on error portion writing the error to a text file or dialog so you can see what happens?

I’m pretty new to AppleScript so I’ll have to learn how to do that. In the mean time I tried some other stuff. If I replace iTunes with any other application, like TextEdit or Mail, the script works beautifully and the activate command at the end goes off too. I thought maybe the file wasn’t done copying so I put a delay of 5 seconds in before starting iTunes but it still won’t work.

Any ideas why iTunes is the only App I can’t call at the end of this script? Could the script be locking the preference file so iTunes can’t read it and aborts?

If a lot of your tunes are ITMS downloads, it might be the song/machine limitation.

So, uh, apparently if you save the script as an application and name it iTunes as well when you run it, the script doesn’t know which iTunes to call. Duh! I’ve attached the whole script below in case anyone finds it useful. Thanks for hearing me out all!

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