Bug in Applescript Call?

The first tell application call works. The second does not. Why not?

property pOFa : "OmniFocus"

tell application "OmniFocus"
   tell content of front document window of default document to set gOFTaskID to the id of every selected tree
end tell

tell application pOFa
    tell content of front document window of default document to set gOFTaskID to the id of every selected tree
end tell

The second throws an error in the compiler … Expected end of line but found class name … with the word “window” highlighted.

The scripts will both work with a simple “activate” call.


JJW

It’s not a bug.
If you use a variable rather than a literal to specify the target, a terms block referring to a local application may be needed to resolve terminology at compile time. The term document window is defined in the OmniFocus dictionary, so Applescript doesn’t understand it.
It wasn’t needed with the activate command because it’s defined in AppleScript itself.

So, you need something like this:

property pOFa : "OmniFocus"

using terms from application "OmniFocus"
	tell application pOFa
		tell content of front document window of default document to set gOFTaskID to the id of every selected tree
	end tell
end using terms from

P.S. Matt Neuberg book about Applescript contains some of this information.

Thank you. I had seen the line using terms from .... Now I understand the details behind it.

Shame that one cannot say using terms from application pOFa. It defeats the purpose of allowing a user to set their application name symbolically when it has to be set again with a dictionary call.

But then, in retrospect, the script I am building works between two apps with names that are essentially immutable. So … Why make the name symbolic in the first place? This is a case where I was too clever for my own good I guess.


JJW

You’re welcome.
The code I wrote it’s mainly used with Remote Apple Events. Maybe you don’t have a live connection to the Mac while you’re writing and compiling the code. For that purpose, you can enclose any code that is aimed at a remote application with the using terms from block. It makes possible to compile the code.
But, as you say, if app names are immutable, it’s not necessary. I think there are edge cases, though.