Launching app only if it exists...?

hey,

pardon my newbie-ness, but…

i’m making a little script to be run on a group of machines, in which there are several programs which can be launched from the script. not all of the programs are present on all of the machines, however.

if the script is run on a machine missing one or more programs, it prompts the user to find the program on the disk, which is not the behavior i want. if the script can’t find the program, the program doesn’t exist! how does one prevent applescript from prompting users to locate these apps…?

Take a look here.

To find out an App’s creator code, do this:

Jon

Here’s a solution using the file ID of applications (all credits to Rob)


try
	tell application "Finder" to set theApp to application file id "TTXT" as string
on error -- the app is not installed...  
	display dialog ¬
		"The application was not found on your system." buttons {"Cancel"} default button 1
	return -- quit script 
end try

Note: The file ID is case sensitive and may contain spaces. The proper case and spaces are required for accurate results. For instance, the example above will likely say that the application was not found, but if the file id is changed to “ttxt”, it should find the TextEdit application. Jon has provided a script (above) to find the correct ID. :slight_smile:

– Rob

Hehe Rob,
I did know about case sensitivety and put it uppercase knowingly… although I should have been more explicit and explain… but then you did!

so, i feel like an idiot having to ask this… but…
what’s the syntax for the snippet you gave me :slight_smile: ?

i’ve fiddled with it for a while, and it can’t find any file that i throw at it…

but, on the plus side, the other stuff you guys threw at me seems to work for those apps i can find the file id for.

Does this help?

Jon

actually, i specifically meant the (choose file) part of it.

an example of what one would put there is what i need…
i’ve been trying stuff like…
return (file creator of (get info for (“/Applications/Foo.app”)))

but, i always get syntax errors, or file not found.

Ah, I love tautology. To get an application’s path as a string you need the creator code and to get that you need the application’s path as a string. In other words:

Now again, this is just for the prep work of your script, after you have the creator code, all you’ll use in a script for distribution is:

Jon

aah yes, the colons.
i didn’t realize that applescript didn’t recognize unix directory structure.

sorry for the frustration, but thanks for the excellent answer.