The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   AppleScripting Omni Apps (http://forums.omnigroup.com/forumdisplay.php?f=46)
-   -   Application file id for OmniOutliner (http://forums.omnigroup.com/showthread.php?t=16804)

timwilson 2010-07-19 05:50 PM

Application file id for OmniOutliner
 
Hi all,

I have OmniOutliner Pro installed, but I want to create an applescript that will work on the Pro or non-Pro version. What's the application file id for standard OmniOutliner?

Alternatively, is there a way to address both versions in one fell swoop?

Thanks.

-Tim

whpalmer4 2010-07-19 10:07 PM

OO3 Pro is com.omnigroup.OmniOutlinerPro3
OO3 is com.omnigroup.OmniOutliner3

I'm not sure it's the best way to do it, but the following worked for a proof of concept:

[code]
set appID to "com.omnigroup.OmniOutlinerPro3"
set hasOOPro to true

try
tell application id appID
activate
end tell
on error
set appID to "com.omnigroup.OmniOutliner3"
set hasOOPro to false
end try

tell application id appID
if hasOOPro then
display dialog "User has OmniOutlinerPro"
else
display dialog "User has OmniOutliner"
end if
end tell

[/code]

timwilson 2010-07-20 09:26 AM

That looks good to me. Thanks.

-Tim

timwilson 2010-07-27 04:44 PM

It turns out that the solution above doesn't work. The only reason it works as written is because there aren't any Omni-specific commands inside that tell. If you try to create a new document, for example, it will fail.

Isn't there any way to efficiently write an AppleScript that will target either OmniOutliner or OmniOutlinerPro (assuming that the script doesn't utilize any Pro-specific commands)?

Perhaps OmniOutliner Pro's scripting system could be written to accept an "OmniOutliner" tell statement and run with the corresponding subset of capabilities. That would make it easier to distribute scripts among end users who might have either version.

-Tim

whpalmer4 2010-07-27 05:44 PM

Hmm. I'm able to create documents, but not rows.

I haven't done a full set of experiments as I'm not willing to reboot my computer at the moment, but it looks like if you just use [code]tell application "OmniOutliner"[/code] that an attempt to use it with the other app will pop up the script editor to have you point out the location of "OmniOutliner" and after that everything is smooth sailing. This would be a problem if you wanted to distribute a Run-only application, but not so much of one if you're just distributing the source of the script.

You might also ask the support ninjas for their advice on this matter via Help->Send Feedback.

RobTrew 2010-07-28 12:44 AM

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,

[B]but[/B] 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 [I]run script[/I] 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[/CODE]

[COLOR="White"]--[/COLOR]

RobTrew 2010-07-28 02:39 AM

e.g.

[CODE]property pCreatorCode : "OOut"

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 CountRows()
tell application " & quote & strName & quote & "
if count of documents > 0 then
tell front document
set strMsg to \"Number of rows in \" & name as string & \" is \" & (count of rows) as string
display dialog strMsg
end tell
end if
end tell
end CountRows
end script
"
set oScript to run script strScript
CountRows() of oScript[/CODE]


All times are GMT -8. The time now is 09:05 AM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.