Applescript click dock item and trigger a menu item

Hi, I am trying to click “Duplex Scan” which is the 1st menu item available when you right click on “ScanSnap Manager” on the Dock. I currently have a script which uses the UI interface I am trying to develop a faster script. With the new script I can’t seem to get to the menu item I want to possibly trigger “Duplex Scan” in the background as it’s much faster than UI scripting.

This is the new script that I am currently working on which is giving me problems:

activate application "Dock"
tell application "System Events"
   tell process "Dock"
      click menu item 1 of menu 1 of UI element "ScanSnap Manager" of list 1
   end tell
end tell

Error message:

System Events got an error: Can’t get menu 1 of UI element “ScanSnap Manager” of list 1 of process “Dock”. Invalid index.

This script is the current script that I use which works perfectly:

tell application "System Events"
   tell process "Dock"
      tell list 1
         perform action "AXShowMenu" of UI element "ScanSnap Manager"
         delay 0.12
         keystroke "Dup"
         keystroke return
      end tell
   end tell
end tell

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

Hi Christopher, I can’t express how helpful this has been. I am very grateful.
Many thanks,
Ali