Re: Language-independent way to find Applications
Re: Language-independent way to find Applications
- Subject: Re: Language-independent way to find Applications
- From: Christopher Nebel <email@hidden>
- Date: Mon, 17 Mar 2008 10:27:24 -0700
On Mar 17, 2008, at 8:40 AM, Thomas Summerall wrote:
I have a script that needs to find an application (Photoshop) by
looking in all the user's application folders.
I'm assuming:
1. There can be two relevant applications folders on any volume
(volume/applications and user/applications)
2. Those two folders can exist on multiple mounted volumes
3. These folders are not called "Applications" on non-English systems
If those are true, is there a way to tell the Finder to direct me to
the various applications folders that will cover all these
contingencies?
Not as such -- the "Applications" folders in the user's home and on
the startup disk are locatable using "path to applications
folder" (adding "from user domain" for the user one), but
"Applications" folders on other disks are not given any special
treatment by the system. You could make a reasonable guess by getting
the name of the system Applications folder and then looking for a
folder of the same name in each disk, but that would only be a guess.
However, all that misses the fundamental point that the user is not
obliged to put applications in the "Applications" folder -- that's
merely a guide. In reality, they could put Photoshop absolutely
anywhere. Fortunately, this doesn't matter (much) to AppleScript --
it uses a system service to locate applications. (Launch Services, to
be precise.) If it's been properly installed, or merely launched,
then a simple 'tell application "Photoshop"' will find it.
However, there's some fine print. 'tell application "Photoshop"'
works as long as you send out a compiled script, because compiled
scripts actually save some extra information to let them locate
applications even if their name has changed. (Users are allowed to do
that.) If you need to use a plain-text script and compile it on the
user's machine, then you'll need to locate the application by id.
There's a formal way to do that in Leopard: 'tell application id
"com.adobe.photoshop"'. (Or whatever its id actually is. 'get id of
application "Photoshop"' to find out.) There are informal ways in
older systems.
This all assumes that you merely need to tell Photoshop to do
something. If you need to find its physical location (so you can put
some files next to it, perhaps), then the most reliable thing would be
to launch it (see above) and then get its location from System Events'
"process" class, as Yvan suggests.
--Chris Nebel
AppleScript Engineering
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden