MacOS – Close menu bar menu with applescript

applescriptautomationmacos

tell application "System Events" to tell process "SystemUIServer"
    tell (menu bar item 1 of menu bar 1 where description is "system sound volume")
        click
    end tell
end tell

will open the sound menu bar item, but I want to delay one second then close it.

I tried:

tell application "System Events" to tell process "SystemUIServer"
    tell (menu bar item 1 of menu bar 1 where description is "system sound volume")
        click
        delay 1
        cancel
    end tell
end tell

but that didn't work

Best Answer

You almost had it. This works for me.

tell application "System Events" to tell process "SystemUIServer"
    tell (menu bar item 1 of menu bar 1 where description is "system sound volume")
        click
        delay 1
        key code 53
    end tell
end tell