Launching Apps from a list

Hi folks. A colleague asked about doing a demo of Expose for his User group and wanted to know how to launch a bunch of apps like Steve Jobs did at the demo.

I wanted to start with a list of app names and code from there. This code, however, launches the named app when it executes the “path to application” expression (!).

Here is my trivial test code:

set theList to {"iPhoto", "iTunes"} -- make a list
repeat with theName in theList --loop
	set thePath to path to application theName -- get the path
end repeat

Can somebody verify if this is launching iTunes and iPhoto on their system, and if so, why?

Thanks in advance!

I don’t think you need the path, just tell the app to activate (or launch):

set theList to {"iPhoto", "iTunes"}
repeat with theName in theList
	tell application theName to activate
end repeat

Tested on Mac OS 10.3.2/AS 1.9.3.


Hey thanks, that (now obviously, duh) works.

I initially tried

set theList to {"iPhoto", "iTunes"}
repeat with theName in theList
	tell application "Finder" to launch application theName
end repeat

Which compiles, but doesn’t launch anything.

And does anybody get the launching with just the “path to application” phrase?

If you’re asking whether iTunes and iPhoto receive the “launch” in your first post, yes, in a sense, but it’s kind of an indirect way of doing it. The “path to application” is meant to be used with an application that is already running, so in order for AppleScript to execute that command, it first has to launch iPhoto and iTunes and tell them the “path to current application” command, which returns an alias to their location on your disk.

For example, I set the list to just iTunes, and I got the following in the “Event Log”:

tell application “iTunes”
path to current application
alias “Mac HD_OSX”
end tell

Hope this helps…

OK - got it now. Sort of. I thought Finder knew where all the apps were on disk. Seems as if it would have to.

So I thought

Tell app “Finder” to get path to application “iTunes”

Would just return

alias “Macintosh”

But apparently it has to launch the app first. Thanks.

To obtain an alias reference to the app without opening the app, use:

tell application "Finder" to application file id "" as alias

– Rob

Works like a charm, thanks.