Hi everyone, the office Wi-Fi network that I log on to every day changes its password daily.
Because I sometimes lose the connection during the day, I’ve set MacOS to remember the connection as I wouldn’t want to find and retype the password every time that happens.
As a result I have to go through the following routine every morning:
Right-click the Wi-Fi icon
Go to Network Preferences
Choose Advanced
Select the Wi-Fi network in question
Click on the Remove Wi-Fi Network button
Return to Network Preferences
Select the Wi-Fi network in question
Enter the new password and connect
Would anyone have any ideas on how to automate at least part of that?
Perhaps there’s a way to make MacOS forget a network at a certain time (e.g. midnight) or on reboot? Thanks much for reading!
It’s a bit hard for me to give an answer that I know to work without being able to test it against your actual set-up, but if you look at the options, you should be able to create a script to run each morning at work to use airport to force WiFi to disconnect, then use networksetup to remove the network you want to forget, then use it again to add the network back that you want to use, and maybe even pass it in the new password you want it to use. You could tie that into a tool like Alfred to pass the password in as a parameter.
Hopefully that all makes sense and gives you the start for a workable solution.
Given the list of networks to forget and to connect to are not necessarily consistent, is there any limitation here for Keyboard Maestro being able to select the right one each time?
I know about the image based click, but if the network was sometimes shown and sometimes had to be scrolled to I think that would be unreliable. Is there another way to ensue the correct network is selected that Keyboard Maestro could utilise?
This seems like it might be possible through a combination of Keyboard Maestro, AppleScript, and shell scripting. Then again, I say that about almost everything.
Do you have administrator / sudo permission on the machine in question? That will determine whether or not I can suggest some things.
Edit 1
Looks like some good AppleScript to use as a starting point here:
For example, this will open the “Advanced…” part of System Preferences’ “Network” pane:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "System Preferences"
activate
reveal anchor "Wi-Fi" of pane id "com.apple.preference.network"
delay 1
tell application "System Events"
tell process "System Preferences"
click button "Advanced…" of window "Network"
end tell
end tell
end tell
The full code on the linked page shows how to remove a Wi-Fi network from the list. You should be able to modify that fairly easily.
I am a KM user. My question was specifically about interacting with the selection in the networks listing. The scripting approach I suggested should allow it to be driven directly by name and I don’t follow yet how KM could achieve equivalent reliability on this. Can you clarify?
Thanks for the ideas everyone! And thanks much Tjluoma for this script, I’ve used it as below and it works great for forgetting the specific Wi-Fi network.
The next thing to figure out would be if it’s possible to tweak the end so it reselects the Wi-Fi network from the pulldown menu in the Network window and make it prompt for the password:
tell application "System Preferences"
activate
reveal anchor "Wi-Fi" of pane id "com.apple.preference.network"
delay 1
tell application "System Events"
tell process "System Preferences"
click button "Advanced…" of window "Network"
delay 1
-- sets focus to the table containing the available Wi-Fi networks
set focused of table 1 of scroll area 1 of tab group 1 of sheet 1 of window "Network" to true
delay 1
keystroke "FIRSTLETTERSOFWIFINETWORKNAMEGOHERE"
delay 0.2
-- this clicks the button "-" to remove that Wi-Fi network from the list
perform action "AXPress" of button 2 of group 1 of tab group 1 of sheet 1 of window "Network"
delay 0.2
perform action "AXPress" of button "Remove" of sheet 1 of sheet 1 of window "Network"
delay 0.2
perform action "AXPress" of button "Apply" of window "Network"
end tell
end tell
quit
end tell
You’d replace “YourSSIDhere” with the actual SSID and the last arg would be a variable with the password.
You could do this with a shell script in Keyboard Maestro after using a “Prompt User For Input” for the password (Use “SSID_PASSWORD” as the variable name in Keyboard Maestro’s “Prompt for User Input” if you want to use “$KMVAR_SSID_PASSWORD” in the shell script.
I’d assume that you could save use the previous SSID_PASSWORD as the default answer in the “Prompt for User Input” just in case you have to reconnect later. It’s not terribly secure, but that’s what happens when you have a stupid policy like changing the Wi-Fi password every day.