I'd like to run a macro periodically If, and only If, my MacBook is at home. The way that is normally proposed to achieve this is to use a Wireless Network Condition, to make the macro run If the home network is connected. But as I sometimes like to work on my computer without being connected to the internet, a better solution for me would be a If-statement for when a given WiFi network is available, as in within WiFi range, but not necessarily connected.
I thought there might be some apple script or something (that I could then run every couple of minutes), that would return a list of all available WiFi networks, but my online searches have not given me any working solutions.
Anyone having any idea about how to do this available WiFi trick? Or any ideas, other than connected WiFi network, on how to make a macro be location specific?
This is how I would structure a KM macro to do this:
Run the macro every so often using a Periodic trigger
In an Execute a Shell Script action run this shell command: /System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s
saving the result to a variable
Search the contents of the variable for the WiFi SSID of interest.
If the SSID is found, do whatever actions you wish
Otherwise terminate the macro.
On my system, running the shell command results in something like this:
SSID BSSID RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
SKYH3X5J 50:70:43:f2:97:42 -76 1 Y -- WPA2(PSK/AES/AES)
VM9141472 20:b8:2b:4f:75:ae -86 108 Y NL WPA2(PSK/AES/AES)
VM7480275 ac:f8:cc:60:d4:52 -89 108 Y GB WPA2(PSK/AES/AES)
Bd Devices ea:cb:ac:35:f2:72 -84 100 Y GB WPA2(PSK/AES/AES)
Bd Wi-Fi e2:cb:ac:35:f2:72 -82 100 Y GB WPA2(802.1x/AES/AES)
R1 b6:b9:8a:4c:89:d3 -23 5,+1 Y -- WPA2(PSK/AES/AES)
SKYA6E2W 00:a3:88:42:55:aa -67 1 Y -- WPA2(PSK/AES/AES)
SKYA6E2W 00:a3:88:42:55:ad -77 36 Y GB WPA2(PSK/AES/AES)
R2 b0:b9:8a:4c:89:d5 -25 48 Y -- WPA2(PSK/AES/AES)
R3 b0:39:56:7b:32:db -64 48 Y -- WPA2(PSK/AES/AES)
So for example searching for whether Bd Wi-Fi is in range is pretty simple.
Note: I'm on Catalina, so YMMV.
Here's what the shell command looks like in KM (it takes a few seconds to run BTW)
If you have the Shortcuts application on your Mac, you could use a shortcut to retrieve your current location. The following macro uses the shortcut depicted below:
This is also an interesting approach! But I thought the Mac only retrieved it's location from what WiFi-network it was connected to? Or does the Mac's location services have more tricks up it's sleeve? Like communicating with my iPhones GPS or something? (Not that I am sure I would necessarily want to share my iPhone's location with my Mac though)
Thought I'd share my finished macro that returns the status of whether my MacBook is at home or not.
Set up like this to only run the somewhat slow script in the rare cases I am disconnected from my WiFi.
It will however, of course, not return a correct value if the WiFi is switched off, not only disconnected.
I will also redo my other location specific macros (that for instance mutes my Mac's audio at the library) so that I do not have to connect to a network for them to be set into effect. This is great!