Using UI scripting to use edit/find in menu

This is my first applescript. I am trying to simulate using edit/find menu in Omnioutliner.

I think my only option is ui scripting. Is this true?

I’m using UI Element Inspector and have the following the following when pointing my mouse to the search string of the find dialog.

<AXApplication: “OmniOutliner Pro”>
<AXWindow: “Find”>

AXRole: “AXTextField”
AXRoleDescription: “text field”
AXHelp: “(null)”
AXValue (W): “xyz”
AXEnabled: “1”
AXFocused (W): “1”
AXParent: “”
AXWindow: “<AXWindow: “Find”>”
AXTopLevelUIElement: “<AXWindow: “Find”>”
AXPosition: “x=704 y=188”
AXSize: “w=468 h=22”
AXTitleUIElement: “”
AXChildren: “<array of size 1>”
AXSelectedText (W): “”
AXSelectedTextRange (W): “pos=3 len=0”
AXNumberOfCharacters: “3”
AXVisibleCharacterRange (W): “pos=0 len=3”
AXInsertionPointLineNumber: “0”

AXShowMenu - show menu
AXConfirm - confirm

I want to change AXValue from “xyz” to “oak”. I use the following script:

tell application “System Events”
tell process “OmniOutliner Pro”
tell menu bar item “Edit”
tell menu “Edit”
tell menu item “Find”
activate menu item “find”
tell window “find”
tell group 1
tell text field 1
set value of text field to “oak”
(perform action “AXPress” of button “Next”)
display dialog searchText
end tell
end tell
end tell
end tell
end tell
end tell
end tell
end tell

I get an applescript error "Can’t set <> of <> to “oak”. Can anyone tell me what I’m doing wrong. I’ve spent a couple of days on this script.

Model: macbook pro
AppleScript: 1.10.7
Browser: Safari 523.12
Operating System: Mac OS X (10.4)


welcome and Merry Christmas :slight_smile:

I have only the simple bundled version of OmniOutliner, but maybe it works also with the Pro version

activate application "OmniOutliner"
tell application "System Events"
	tell process "OmniOutliner"
		click menu item "Find..." of menu 1 of menu item "Find" of menu 1 of menu bar item "Edit" of menu bar 1
		repeat until exists window "Find"
		end repeat
		tell window "Find"
			set value of text field 1 of group 1 to "oak"
			--	click button "Next"
		end tell
	end tell
end tell

Thanks Stefan :slight_smile:

Merry Christmas to you also.

I got your script to work but with a minor change. The repeat went into an infinite loop. I fixed it by putting a delay statement right before the repeat. Thanks for putting the “click button” statement in your example. That was my next step.

My next step now is to somehow remember my insert cursor position in the document and have another script return me to my original position after I do the find. However, I think I need a break from applescript after this.


This works as a stand alone script but when I run the script from the omni outliner document specific toolbar I get

The script “FindDef” could not complete
AppleScript reported the following error
System Events got an error:
NSReceiverEvaluationScriptError: 4

Any ideas on how to fix this?