Script won't open in editor if application id does not exist

I use a script that tests for the existence of an application by asking the Finder to check a specific application id (for the free Nisus Thesaurus), and if the application id exists on the system, then the script reads a text file and looks up the word in the Thesaurus.

Here are the basics (NB: “thisFile” is a file written to the folder that is being watched by this script, which runs as a launch daemon that watches a folder for new files - like a folder action script, but faster):

tell application "Finder"
		try
			get application id "com.nisus.NisusThesaurus"
			set nisusExists to true
		on error
			set nisusExists to false
			activate
			display dialog "Nisus Thesaurus not found on this OS X system." & return & return & "Download it from [url=http://www.nisus.com]www.nisus.com[/url]" buttons {"OK"} giving up after 10
		end try
	end tell
	
	if nisusExists is true then
		set thesText to (open for access thisFile)
		set lookUpTerm to (read thesText)
		close access thesText
		tell application id "com.nisus.NisusThesaurus" to activate
		tell application "System Events"
			set frontmost of process "Nisus Thesaurus" to true
			tell process "Nisus Thesaurus"
				tell window 1
					set value of combo box 1 to lookUpTerm
					click button 4
				end tell
			end tell
		end tell
	end if

My question is this: if the Nisus Thesaurus application is in the trash or otherwise not installed, the script works, but I can’t open it in the AppleScript Editor.

Is there a way to modify the script so that it still works correctly, but can be opened in the AppleScript editor even if the application id is not present?

Thanks for any advice.

Hello.

I haven’t tested this with anything that is in the trash, but I believe that if an app is in the trash, then it won’t return a path. I’ll leave that test to you. :wink:

set A to path to application id "com.nisus.NisusThesaurus"

Thank you!

First, you are right: if an app is in the trash, the same error occurs that occurs when it does not exist at all.

Second, unfortunately, this fix does not solve the problem that my script won’t open in the editor when the Nisus Thesaurus is either absent or in the trash. There must be some other problem that I can’t identify. If you have any other ideas, I would be very glad to see them!

This might help (“using terms from”):

https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/reference/ASLR_control_statements.html

Thank you. That looked as if it should work, but (if I understand it correctly) it requires the application to be present on the local machine.

This is not a serious problem. I can get around it by including a text-only version of the script in the application bundle, which should be editable even if the script itself is not. But of course it would be nice to have a cleaner solution!

Hello. :slight_smile:
When I save a script like below, well, first of all, I am asked where I’d find the app, when I save it, so I hit cancel, and the editor (ScriptDebugger) lets me compile the script anyway.

I Save the script, and then I open it with AppleScript Editor, surmising that’s the one you use.

So I am asked, a couple of times where I’d find Nisus, and I reply with a cancel, AppleScript editor gives up after I have hitting cancel twice, and I am allowed to edit the script!

(I don’t have Nisus Thesaurus.)

using terms from application "Nisus Thesaurus"
	
	display dialog "message"
end using terms from

Well, this is odd:

For reasons that I don’t understand, my script will now open in the AppleScript Editor even with Nisus Thesaurus not present on the system.

For the past two days, it refused to open in the AppleScript Editor. Now it does. I can’t imagine why this happened.

I realize I’ve wasted a lot of people’s time by asking about a problem that solved itself mysteriously. So at least let me thank everyone who offered an answer.

McUsrII: Your experience is the same as mine - usually! I press Cancel a couple of times, and the script opens. But in this instance, I got an error message saying that the script could not be opened - I never got a chance to press Cancel when asked where Nisus Thesaurus is. I tried to make a screen shot showing the problem - and the problem didn’t occur!

When “Nisus Thesaurus” is not installed, then the script (as is) cannot be compiled because of the line

tell application id "com.nisus.NisusThesaurus" to activate

Replacing it with

tell application "Nisus Thesaurus" to activate

allows the script to be compiled and saved.

Once saved, it can be reopened in the ASE in the absence of “Nisus Thesaurus” but, you’ll have to Cancel the “Choose Application” dialog box twice in succession.

I also think that the script could be simplified a bit:

tell application "Finder"
	try
		set thesText to (open for access thisFile)
		set lookUpTerm to (read thesText)
		close access thesText
		tell application "Nisus Thesaurus" to activate
		tell application "System Events"
			set frontmost of process "Nisus Thesaurus" to true
			tell process "Nisus Thesaurus"
				tell window 1
					set value of combo box 1 to lookUpTerm
					click button 4
				end tell
			end tell
		end tell
	on error
		activate
		display dialog "Nisus Thesaurus not found on this OS X system." & return & return & "Download it from [url=http://www.nisus.com]www.nisus.com[/url]" buttons {"OK"} giving up after 10
	end try
end tell

Flex20,

Everything you suggested works perfectly - and thank you for the more efficient script. This is a great help, and you’ve clarified some things that I never fully understood.

Thank you again!