Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Let's say I want to click a button that appears somewhere within a window, using AppleScript. click button works, but you have to know which button exactly you want to press.


For example: Scanning is a bit cumbersome when you always have to wait for the scanner to finish, then switch to Image Capture.app, then click Scan again.

So, I want to automate clicking this button here …

enter image description here

Well, I thought that would be relatively easy, but in the beginning this is as far as I got:

tell application "System Events"
    tell process "Image Capture"
        click button "Scan" of window "Image Capture"
    end tell
end tell

Of course, the button is buried deeper than that (i.e. in some Split Group).

With the Accessibility Inspector I can see where it is, but do I really have to go down the UI element tree to find the button? Is there any shortcut? If not, what am I missing in click button "Scan" of window "Image Capture"?

enter image description here

More general: Where do I find a button in the UI element hierarchy?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

If the button is not available directly, you might have to guess.

What worked for me was:

tell application "System Events"
    tell process "Image Capture"
        click button "Scan" of group 1 of splitter group 1 of window 1
    end tell
end tell

Another workaround would be to activate the window and press the space bar:

tell application "Image Capture"
    activate
    tell application "System Events" to key code 49
end tell

You can actually try to near it down by running commands like:

UI elements of window 1
UI elements of splitter group 1 of window 1
UI elements of group 1 of splitter group 1 of window 1

or, as @Lri said in the comments:

properties of UI elements of window 1
properties of UI elements of UI elements of window 1

This will present you with a list of elements contained, and you can guess your way from there.

share|improve this answer
2  
UI Browser also shows the integer indexes used by System Events, and can display all UI elements of an app in a column view. It's $55 though. ▪ A possibly faster way to narrow down elements manually: properties of UI elements of UI elements of window 1 –  ؘؘؘؘ Sep 18 '11 at 19:41

This has worked for me:

entire contents of window 1

when this came up short:

UI elements of window 1
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.