launch application with command key down

If you launch iTunes while holding the option key, itunes will allow you to access multiple libraries, but you must manually browse to the location of the library each time.

I am trying to create a launcher with applescript that will automate this.

Where I am stuck is launching itunes while simulating option key down.

Alternatively, if there is a way to launch an application from the shell, giving that application the same instructions or whatever that it gets when you launch it from finder while holding down the option key, I could use “do shell script” and that would work too.

Here is the code that I tried, but which did not work:

on appIsRunning(appName)
	tell application "System Events" to (name of processes) contains appName
end appIsRunning

tell application "System Events"
	key down option
end tell

tell application "iTunes"
	activate
end tell

repeat until appIsRunning("itunes") = true
	delay 1
end repeat

tell application "System Events"
	key up option
end tell

do shell script "say itunes is open"

The result of this script is that itunes opens, the terminal speaks “itunes is open” and the letter “a” is appended to the end of the text in Script Editor.

EDIT:

This also doesn’t work:

tell application "System Events" to tell application "itunes" to activate using option down

In fact, the problem might be with the simulated key press. If I run this code (which takes 10 seconds to execute) and manually launch itunes while it is running, it does not achieve the desired effect:

tell application "System Events"
	key down option
	delay 10
	key up option
end tell

Hi,

I haven’t tested it, but it might be easier to alter the keys iTunesRecentDatabasePaths and iTunesRecentDatabases in ~/Library/Preferences/com.apple.iApps.plist
Make sure that iTunes is closed while changing the keys.

iTunesRecentDatabasePaths is an array containing one file URL string
iTunesRecentDatabases is an array containing one path string

Hey that worked perfectly. Thanks a bunch for the help!