If you don't mind using a 3rd party utility, here's an example AppleScript script that uses cliclick
:
tell application "System Events"
tell application process "SystemUIServer"
set theWiFiProperties to item 1 of (get properties of every menu bar item of menu bar 1 whose description starts with "Wi-Fi")
end tell
set theXpos to (item 1 of position in theWiFiProperties) + ((item 1 of size in theWiFiProperties) / 2) as integer
set theYpos to (item 2 of position in theWiFiProperties) + ((item 2 of size in theWiFiProperties) / 2) as integer
end tell
tell current application
do shell script "/path/to/cliclick kd:alt c:" & theXpos & "," & theYpos & " ku:alt"
end tell
- Note: Change
/path/to/cliclick
to the actual pathname
of the cliclick
executable.
How it works:
The theWiFiProperties
variable gets set to the properties
of the Wi-Fi
menu extra and then the variables theXpos
and theYpos
get set to a position that together is the center of the Wi-Fi
menu extra on the menu bar.
This info is then used in a do shell script
command using cliclick
to press the option key down, click at the designated x,y
coordinates and let the option key up.