Detect if in a text field, don't trigger command?

Hi all,
I'm trying to use a single-key shortcut in Omnigraffle, but only run the command when I'm not typing inside a text field.

I got this:

tell application id "OGfl"
	set lstSeln to selection of front window
	set oShape to item 1 of lstSeln
	tell canvas of front window
		if value of attribute "AXFocused" of "AXTextArea" of oShape is 1 then
			return "TRUE"
			-- exit. do nothing, user is inside a text field.
		else
			return "FALSE"
			-- ok, run command!
			-- **command here**
		end if
	end tell
end tell



<AXApplication: “OmniGraffle”>

<AXWindow: “Untitled”>



Attributes:
AXFocused (W): “1”
AXChildrenInNavigationOrder: “<array of size 0>”
AXSelectedText (W): “”
AXInsertionPointLineNumber: “0”
AXPosition: “x=387 y=401”
AXNumberOfCharacters: “11”
AXSharedTextUIElements: “<array of size 1>”
AXSelectedTextRange (W): “pos=11 len=0”
AXHelp: “(null)”
AXChildren: “<array of size 0>”
AXRole: “AXTextArea”
AXParent: “”
AXTopLevelUIElement: “<AXWindow: “Untitled”>”
AXSharedCharacterRange: “pos=0 len=11”
AXSelectedTextRanges (W): “<array of size 1>”
AXVisibleCharacterRange (W): “pos=0 len=11”
AXValue (W): “hello world”
AXRoleDescription: “text entry area”
AXSize: “w=251 h=21”
AXWindow: “<AXWindow: “Untitled”>”
AXTextInputMarkedRange: “pos=11 len=0”
AXFrame: “x=387 y=401 w=251 h=21”

Actions:
AXShowMenu - show menu

Hey @hello,

This sort of thing gets very problematic when you are trying to have the keys perform normally in text fields.

You can make System Events send a keystroke:

tell application "System Events"
   keystroke "n"
end tell

I'll be surprised if you can make this work smoothly enough to satisfy, but you never know.

In any case – take a look at this:

Single-Key macros

This is how I manage single-key hotkeys when I want them.

-Chris

hi @ccstone, thanks!
yeah, figured it'd be an uphill battle.
I'll just remember to deselect it :slight_smile: