AppleScript to Option-click on the Dropbox Menu Bar Icon

applescriptdropboxkeyboardmenu bar

I have an AppleScript that does a simple "mouse" click on the Dropbox menu bar icon (Menu Extra or Menulet). It works well.

tell application "System Events"
tell UI element "Dropbox"
    tell menu bar item 1 of menu bar 2
        perform action "AXPress"
    end tell
end tell
end tell

I want to edit this code so the action that will be performed is a click while the Option (alt / ⌥) is pressed down.

I've done an extensive search for a solution but didn't find any.

Thanks in advance.

Best Answer

Using terms from the (FREE) AppleScript Toolbox scripting addition, this code will handle your question.


The code in this updated answer will automatically get the coordinates of the DROPBOX icon in the status bar... Whether it's location stays the same or changes


tell application "System Events"
    tell its UI element "Dropbox"
        tell its menu bar 2
            set originalCoordinates to position
        end tell
    end tell
end tell

set itemOne to (item 1 of originalCoordinates) + 10
set itemTwo to (item 2 of originalCoordinates) + 10

set dropboxMouseLocation to {itemOne, itemTwo}
AST set mouse point location dropboxMouseLocation
AST click at dropboxMouseLocation holding modifier key ast option key

enter image description here


UPDATE

This is following version of the code will return the mouse to where its original location was before clicking on the Dropbox status menu icon


set originalMouseLocation to AST mouse point location

tell application "System Events" to tell its UI element "Dropbox"
    tell its menu bar 2
        set originalCoordinates to position
    end tell
end tell

set itemOne to (item 1 of originalCoordinates) + 10
set itemTwo to (item 2 of originalCoordinates) + 10

set dropboxMouseLocation to {itemOne, itemTwo}
AST set mouse point location dropboxMouseLocation
AST click at dropboxMouseLocation holding modifier key ast option key

AST set mouse point location originalMouseLocation