GUI scripting: simulate "button release"

hi,

I (kind of) successfully tried to click a button by GUI scripting - but the expected action of the target application isn’t executed, while the visual feedback of the button is displayed.
I realized that the action - when clicking the button “manually”, takes place on releasing the button.
Is there a way to explicitely press and release a button (preferably without using ES)?
or could it be another problem, demanding another solution?

thanks for any hint!!

jan klug

ps… edit… of course, most buttons perform their action upon release it seems, so i’m afraid this was a not very intelligent question… sorry…

what button in what application are you attempting to push ?

mm

hi mcgrailm,

it’s the “Shoot” button of Nikon’s “Camera Control Pro”…

tell application "System Events"
	tell process "Camera Control Pro"
		set frontmost to true
		tell button "Shoot" of window "Camera Control Pro"
			click
		end tell
	end tell
end tell

…just lets the button flash blue, but thats it…
any ideas welcome!

thanks,
jan

I take it this program is not scriptable ?

you may need to say something like…


tell application "Camera Control Pro" to activate
tell application "System Events"
       click button "Shoot" of window 1 of application process "Camera Control Pro"
end tell

I don’t have that app so I’m not sure if that will work or not

thanks for the answer!

i tried it with

tell application "Camera Control Pro" to activate
tell application "System Events"
	click button "Shoot" of window "Camera Control Pro" of application process "Camera Control Pro"
end tell

but that gives the same result…

jan

is there no dictionary for this app ?

here is a program that may help you http://developer.apple.com/samplecode/UIElementInspector/index.html

I try to stay away from gui scripting so if you can find a way to do the same thing without the gui thats what I would recommend

mm

unfortunately not a big dictionary…
just standard stuff, it seems.

i used UIElementinspector to find the button in the GUI; seems to work, as it flashes when i run the script - but the action that the button should trigger doesn’t happen.

this is the output of UIElementinspector:

<AXApplication: “Camera Control Pro”>
<AXWindow: “Camera Control Pro”>
<AXButton: “Shoot”>

Attributes:
AXRole: “AXButton”
AXRoleDescription: “button”
AXParent: “<AXWindow: “Camera Control Pro”>”
AXTitle: “Shoot”
AXWindow: “<AXWindow: “Camera Control Pro”>”
AXTopLevelUIElement: “<AXWindow: “Camera Control Pro”>”
AXPosition: “x=227 y=148”
AXSize: “w=120 h=20”
AXEnabled: “1”
AXFocused (W): “0”

Actions:
AXPress - press

does this show any other possibility than using ‘click’?

thanks again,

jan

ps. yes, i’d really like to avoid GUI scripting - but Nikon doesn’t really offer much help here, I’m afraid…

is the button you are trying to click the default button ?

if so you could try…


tell application "Camera Control Pro" to activate
tell application "System Events"
  keystroke ASCII character 3
-- or 
-- keystrokee return
end tell

mm

unfortunately not…

also, there’s no menu item that i can give a key combination that could be scripted.
but…
just for fun, i tried to add a keyboard shortcut to “Shoot” anyway, and discovered that it worked!!

so now this works:


tell application "Camera Control Pro"
	activate
end tell
tell application "System Events"
	key code 17 using {command down, shift down}
end tell

…which is an ugly hack, but way less ugly than what i came up with before (positioning the window thru applescript, simulate a mouseclick thru max/msp…)

thanks for the help!!
makes me want to look deeper into applescript (and send a mail to Nikon that they’ll also do, so that I can also control the other aspects of the camera thru scripting…)

Jan

I see you found your solution. Here’s a thought in case you run into other problems…

Can you use the tab key to get to the button? If you set “full keyboard access” to “all controls” in the “keyboard shorcuts” tab of the “keyboard & mouse” preference pane, then sometimes you can get to the control you want with a series of “keystoke tab” commands. You can check this manually by pressing your tab key to find which areas of a window you can access. Then once you’re on the button you can “keystroke return” or “keystoke space” to press it.