if app does exist then do something if not then display dialog help!

Hi, i’m relatively new to scripting, so I hope i haven’t missed something basic here.

I am trying to write a script that says “if Microsoft Entourage exists, then post the contents of the clipboard into a new email. If it doesn’t exist, then display a dialog saying leave contents on clipboard.”

This is what i’ve come up with, and it works if entourage is installed, but if it’s not, it displays a dialog asking you to select an app.

Can anyone tell me where i’ve gone wrong?

tell application "Finder"
	if (exists application file id "com.microsoft.entourage") then
		
		tell application "Microsoft Entourage"
			set theSubject to "system information"
			set theBody to the clipboard
			set theMessage to make new outgoing message with properties {subject:subject, content:content}
			set theRecipient to {address:{display name:"recipient", address:"recipient@company.org"}, recipient type:to recipient}
			set theMessage to make new outgoing message with properties {recipient:theRecipient, subject:theSubject, content:the clipboard}
			open theMessage
		end tell
		
	else if (exists application file id "com.microsoft.entourage") is false then
		display dialog ¬
			"Entourage is not installed. " & " click OK to leave results on the clipboard"
		
	end if
end tell

Hi,

actually everything is fine.
The problem occurs, when Entourage is not installed and the script gets recompiled.
So make sure that it couldn’t be recompiled (e.g. by saving it as application bundle).

I recommend to avoid the wrapping Finder tell block


tell application "Finder" to set entourageExists to (exists application file id "com.microsoft.entourage")
if entourageExists then
	tell application "Microsoft Entourage"
		set theSubject to "system information"
		set theBody to the clipboard
		set theMessage to make new outgoing message with properties {subject:subject, content:content}
		set theRecipient to {address:{display name:"recipient", address:"recipient@company.org"}, recipient type:to recipient}
		set theMessage to make new outgoing message with properties {recipient:theRecipient, subject:theSubject, content:the clipboard}
		open theMessage
	end tell
else
	display dialog "Entourage is not installed. " & " click OK to leave results on the clipboard"
end if


The above line will error if entourage is not installed. The Finder tries to resolve application file id “com.microsoft.entourage” and errors if it can’t.

Note that like StefanK I would avoid telling applications to do things they’re not required to do. This became a stringent applescript policy in 10.6. We see lots of unlikely errors when this policy is not adhered to so it’s best to be safe than sorry. Therefore you can move a couple other things outside of the Entourage tell block of code. In addition, you had 2 lines where you used “set theMessage to make new outgoing message with properties”. Plus your last display dialog line is a little messed up. So all together I would write your script like the following.

As StefanK mentioned distribute it as a compiled application to avoid having to recompile it on other computers.

set entourageExists to false
try
	tell application "Finder" to set entourageExists to (exists application file id "com.microsoft.entourage")
end try

if entourageExists then
	set theSubject to "system information"
	set theBody to the clipboard
	tell application "Microsoft Entourage"
		set theRecipient to {address:{display name:"recipient", address:"recipient@company.org"}, recipient type:to recipient}
		set theMessage to make new outgoing message with properties {recipient:theRecipient, subject:theSubject, content:theBody}
		open theMessage
	end tell
else
	display dialog "Entourage is not installed. Click OK to leave results on the clipboard"
end if