View Single Post
I haven't tested this hypothesis (only one version of OO on my system) but I think that both versions share the same "creator code" (OOut) so you should be able to write code like that below,

but the problem remains that the library reference will be resolved too late to retrieve any properties or commands that are specific to OO. Their names will appear to Applescript to simply be variable names ...
(no problem, however, in referring to any classes, like 'document', that are defined in the standard Applescript libraries)

(If you look at the code below it will probably occur to you that it is not impossible to put the whole of your script into a string literal, patching the string with the name of the appropriate application, and then running it with the run script idiom. This approach does indeed give full access to the OO-specific libraries, but you may find it a little messy and hard to maintain ... It also brings a bit of a performance cost)


Code:
--- GET A REFERENCE TO WHICHEVER VERSION OF OO IS RUNNING

property pCreatorCode : "OOut"
property pOmniOutliner : missing value

tell application id "com.apple.systemevents"
	try
		set procOO to first process where creator type is pCreatorCode
	on error
		display dialog "OmniOutliner is not running"
		return
	end try
	set strName to name of procOO
end tell

set strScript to "
script
	on GetAppRef()
		return application " & quote & strName & quote & "
	end GetAppRef
end script
"
set oScript to run script strScript
set pOmniOutliner to GetAppRef() of oScript


--- NOW USE THE VERSION-INDEPENDENT IDIOM:  tell pOmniOutliner

tell pOmniOutliner
	if (count of documents) > 0 then
		tell front document
			display dialog name as string with title "Front OmniOutliner Document"
		end tell
	else
		display dialog "No Documents open in OO"
	end if
end tell
--

Last edited by RobTrew; 2010-07-28 at 02:03 AM..