AppleScript

Last updated: May 19, 2020

Discovering available UI elements

tell application "System Events"
    tell process "Application Name Here"
        set visible to true
        return every UI element of front window
        
        -- Swap to this return to get element names
        -- return name of every UI element of front window
    end tell
end tell

This may need to be used iteratively, e.g. look at the output and then change to return every UI element of group 1 of front window, etc.

You can also use the Accessibility Inspector, which is in /Applications/Xcode.app/Contents/Applications/Accessibility Inspector.app.

If you’re willing to shell out $55, you can use UI Browser. This is an application that allows you to navigate the UI hierarchy of an application and copy the AppleScript reference for specific UI elements. It’s much more functional for writing automation in AppleScript than Accessibility Inspector.

Discovering properties of UI elements

tell application "System Events"
    tell process "Application Name Here"
        set visible to true
        repeat with theElem in (UI elements in window 1)
            set theProps to properties of theElem
            log theElem
        end repeat
    end tell
end tell

You can also look at just a specific property like description with set theProps to description of theElem.