views:

88

answers:

2

I hope this isn't too obvious, but I'd like to press one of the toolbar buttons within an application by means of AppleScript.

Background: The button doesn't have any menu item or keyboard shortcut. Thus, I can't activate it by any of those methods; I need to find an AppleScript way of actually 'pressing' the button.

A: 

Ok, that was simpler than I thought, once I found out how. (Googling it didn't leave much help at all, but an application called Prefab UI Browser did the trick finding out how this is done).

Example:

tell application "System Events"
    tell process "OmniFocus"
        click button 3 of tool bar 1 of window 1
    end tell
end tell

I've got a follow-up question, though:

How do you reference a toolbar button by name/description? I know for a fact that the button has a description attribute with the value: "Contexts". But again, how do I reference it in the click statement?

hced
+1  A: 

Ah, figured out that one myself, too. Seems I'm on a self-commenting spree here.

This example worked for me, referencing a specific toolbar button by means of its description attribute:

tell application "System Events"
    tell process "OmniFocus"
        click (every button whose description is "Contexts") of tool bar 1 of window 1
    end tell
end tell

I'll leave it up for any commenters with an opinion about referencing every button whose descripton is "Contexts" (as per my example), to express those down below. But I presume there can't be multiple buttons with the same description, right?

hced