EndNote X and UI Scripting

I’m using EndNote X on Mac OS X v10.3.9. EndNote has a toolbar search box à la Mail or Address Book, but there’s no way to activate it from the keyboard, which is annoying. I’m trying to write a small Applescript to do this task, using UI scripting, because EndNote does not support AppleScript.

Here’s the problem: Whatever I try, my script can’t activate the search text field. I can change the text in the text field (that’s how I know I’m addressing the correct UI element), but I can’t set the keyboard focus to it. I tried various things (the script below shows them), but nothing worked. Any suggestions? TIA!

tell application "System Events"
	tell process "EndNote X"
		set frontmost to true
		tell window 1
			set theBox to text field 1 of group 1 of tool bar 1
			set value of theBox to "Macintosh" --this works
			set focused of theBox to true --(1) generates error* 
			set properties of theBox to {focused:true} --(2) no result
			tell theBox to activate --(3) no result
			set theProps to properties of theBox --(4)
			set focused of theProps to true --(4)
			set properties of theBox to theProps --(4) generates error
		end tell
	end tell
end tell
  • This generates a NSInternalScriptError, although, according to the System Events dictionary, it’s Boolean and it’s not a read-only property.

This works indeed. So that’s the way to set the focus. Thank you very much, Jacques – I shouldn’t’ve found it by myself in a million years.

Cheers, Alex