1

I've searched a lot for this, but all answers talk about how bringing a whole window (or dialogue.. which is still a window really) into focus via activate etc.

But I couldn't find any way of detecting if a specific UI element was selected, in focus etc.

enter image description here

I'm wrote an apple script that automatically jumps to alfred create custom web search, but the script failed when the features tab wasn't selected by default.. so this is what my code looks like:

tell application "System Events"
    keystroke "," using command down
    delay delay_time
    tell process "Alfred Preferences"
        delay delay_time
        -- hack: to ensure that the the "Default results" button isn't selected
        -- by default, we select another tab first, then select the "features" tab
        click button "Appearance" of toolbar 1 of window 1
        click button "Features" of toolbar 1 of window 1
        delay delay_time
        UI elements of scroll area 1 of window 1
        -- bring the left menu to focus first (see hack above, without hack this would work sometimes only)
        keystroke tab

I'd much rather not do this nasty hack (which causes the app to flicker rapidly between tabs whenever i call the shortcut).. i'd rather make a simple if else statement.. ideas?

1

This definitely works on my system running Alfred 3. You may need to adjust the delay times but as they are now, this script works for me.

activate application "Alfred Preferences"
delay 1.5
tell application "System Events"
    tell process "Alfred Preferences"
        click button "Features" of toolbar 1 of window "Alfred Preferences" of application process "Alfred Preferences" of application "System Events"
        delay 1
        set selected of row 3 of table 1 of scroll area 1 of window "Alfred Preferences" of application process "Alfred Preferences" of application "System Events" to true
        delay 1
        click button "Add Custom Search" of tab group 1 of window "Alfred Preferences" of application process "Alfred Preferences" of application "System Events"
    end tell
end tell
  • What's the difference between "axpress" and system event "click"? Bc I tried the click event on a coordinate and nothing happened.. – abbood Feb 17 '17 at 5:36
  • I try limiting myself to script editor only most of the time but when I get all jammed up and don't know what the heck to do, I fire up UI Browser app and select elements in the application I am trying to script and UI Browser will generate the AppleScript commands for me and place them right into script editor. So to answer your question, "AXPress" is the command that UI Browser generated for me – wch1zpink Feb 17 '17 at 5:43
  • is this the ui browser app you're talking about? pfiddlesoft.com/uibrowser – abbood Feb 17 '17 at 6:10
  • That's the one I was talking about – wch1zpink Feb 17 '17 at 6:11
  • i'm afraid it doesn't work.. using its syntax it replaced my own code with this, and it just doesn't work or at least not reliably. – abbood Feb 17 '17 at 6:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .