"Telling" applications with variable names

Hi everyone,

I’ve been searching around for this for several hours now, and I haven’t come to a definitive answer. I’m hoping someone here will know the best approach. I’m building a script (this is the final piece) that will parse some text and write the result to OmniOutliner or OmniOutliner Pro, whichever is installed. Here’s how I’m determining which version is available:

set outlinerApp to ""  -- Assume that OmniOutliner isn't installed at all and do something else instead later
tell application "Finder"
	try
		exists application file id "com.omnigroup.OmniOutliner3"
		set outlinerApp to "com.omnigroup.OmniOutliner3" -- OmniOutliner
	on error
		false
		try
			exists application file id "com.omnigroup.OmniOutlinerPro3"
			set outlinerApp to "com.omnigroup.OmniOutlinerPro3" -- OmniOutliner Professional
		on error
			false
		end try
	end try
end tell

Later on in my script when I actually try to create the OmniOutliner document, it’s failing because it can’t get access to the OmniOutliner dictionary. This is my code:

tell application id outlinerApp  -- The variable I assigned above
	set newDoc to make new document at beginning of documents
	tell newDoc -- set up some defaults for the new document
		set status visible to false -- hide checkboxes
	end tell

        -- Other steps skipped for brevity
end tell

I’ve read and read about the “double tell” and a few other solutions, but they seem to pertain to much older version of OS X or AppleScript.

What’s the current best practice to accomplish something like this?

-Tim

Hi,

to resolve terminology at compile time, applications must be specified by a literal string.
If both versions of OmniOutliner have the same AppleScript dictionary you can use a using terms from block


tell application id outlinerApp -- The variable I assigned above
	using terms from application "OmniOutliner3"
		set newDoc to make new document at beginning of documents
		tell newDoc -- set up some defaults for the new document
			set status visible to false -- hide checkboxes
		end tell
		-- Other steps skipped for brevity
	end using terms from
end tell

If you want to share the script to be run on machines which have only one version installed,
you must compile the script on a machine with both versions installed and save it as application
or something that prevents the script from being recompiled.

Thanks, Stefan,

Do the AppleScript dictionaries need to be identical, or would your suggestion work if they shared the subset of commands that I use in my script? I’m certainly not using any advanced OmniOutliner Pro commands in my simple script. OmniOutliner Pro just happens to be the version that I use.

-Tim