Applescript click dock item and trigger a menu item

Hey Ali

You’re on the right track with the script that works.

You’ve got to get the menu open, before you can select items in it.

tell application "System Events"
   tell application process "Dock"
      tell list 1
         tell UI element "Safari"
            perform action "AXShowMenu"
            tell menu "Safari"
               tell menu item "New Window"
                  perform action "AXPress"
               end tell
            end tell
         end tell
      end tell
   end tell
end tell

I used UI Browser to get the reference to Safari in the Dock.

Then I did this:

tell application "System Events"
   tell application process "Dock"
      tell list 1
         tell UI element "Safari"
            
            {¬
               properties, ¬
               UI elements, ¬
               attributes, ¬
               actions, ¬
               null}
            
         end tell
      end tell
   end tell
end tell

It doesn’t return any UI elements, but you can show the menu.

So I worked down the tree by using perform action “AXShowMenu” and then my little block of diagnostics again just like this:

tell application "System Events"
   tell application process "Dock"
      tell list 1
         tell UI element "Safari"
            perform action "AXShowMenu"
            
            {¬
               properties, ¬
               UI elements, ¬
               attributes, ¬
               actions, ¬
               null}
            
         end tell
      end tell
   end tell
end tell

Until I arrived at the first script (above).

You should be able to do the same thing for ScanSnap.

Okay, let’s make my little diagnostic tool a little easier to use:

tell application "System Events"
   tell application process "Dock"
      tell list 1
         tell UI element "Safari"
            perform action "AXShowMenu"
            
            set diagnosticsList to {¬
               "----- PROPERTIES -----", ¬
               properties, ¬
               "----- UI ELEMENTS -----", ¬
               UI elements, ¬
               "----- ATTRIBUTES -----", ¬
               attributes, ¬
               "----- ACTIONS -----", ¬
               actions, ¬
               "----- END -----"}
            
         end tell
      end tell
   end tell
end tell

-Chris

1 Like