2

I would like to click on the Wi-Fi icon with the option key down to reveal extra options available on Mac. How can I automate it using AppleScript?

I tried using key down option and click menu item but no luck in revealing special options.

Is there any way I can achieve this?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Giri Prasad
  • 1,175
  • 2
  • 8
  • 13

3 Answers3

2

It's currently not possible to click with a key held down using AppleScript. Key down actions only apply to other key press actions, since the AppleScript click action doesn't actually perform a ‘click’, but rather directly actions the element.

grg
  • 5,023
  • 3
  • 34
  • 50
2

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.

user3439894
  • 7,266
  • 3
  • 17
  • 28
1

You can use Automator and record the process using “Watch me do” and then save the automated workflow as an application or a dictation command.

enter image description here

In Automator, I saved the watch me do action as an application. I named this new application “Extended_Wifi.app”. Then I had to add this application in system preferences to be able to control my computer.

enter image description here

Personally, I prefer to use Scripteditor rather than Automator because a huge part of me feels like using Automator is cheating. But at the end of the day, I was able to save the Automator action as an application and it functions perfectly however in Scripteditor, I Could not get the AppleScript version of the action to function correctly.

Here is a quick .gif showing the Automator application working correctly.

enter image description here

wch1zpink
  • 3,026
  • 1
  • 8
  • 19
  • 1
    I tried this. when I execute the code generated by automator it simply click but is not revealing other options. – Giri Prasad May 25 '17 at 15:14
  • In Automator when I started the recording using watch me do, I held down the option key and kept it down as I clicked on the Wi-Fi icon in the menu bar – wch1zpink May 25 '17 at 15:16
  • I did the same. after that I am trying to copy events into script editor so that it will generate the applescript for that . When execute that applescript it is not revealing the extra options. – Giri Prasad May 29 '17 at 06:58