Sonoma Wireless Compatibility Workaround no longer working?

Hello fellow automators!

I'm on Sonoma and have KM macros that trigger when I change WiFi Networks. As documented here, I've needed to use this workaround:

Has anyone else noticed that it doesn't work anymore?

Now, when I run the command, I get an empty result. Digging deeper, I see this:

5907 ➜ /System/Library/PrivateFrameworks/Apple80211.framework/Resources/airport
WARNING: The airport command line tool is deprecated and will be removed in a future release.
For diagnosing Wi-Fi-related issues, use the Wireless Diagnostics app or the wdutil command line tool.

I was going to try to make it work with the wdutil command, but it looks like that requires root/sudo access, which I don't think KM will have?

Triggers work "instantly", but other attempts to get the information will involve "polling."

Some forms of polling will involve using the keyboard, mouse and screen. But naturally if the user is using those things, then that sort of polling will not work. Do you want your polling to work when the user is using the machine, or are you willing to wait until the machine is IDLE? If the latter, I might have a solution for you, which involves FindImage and OCR.

Perhaps sudo doesn't require a password if your Mac doesn't have a password. I don't know if that would work, but I would love to have someone test that for us. But that would be very insecure to have no password on your Mac. But then again, you seem interested in having KM enter your password into sudo, which is not secure either. So maybe you are willing to compromise security to get this to work.

There is a solution for wdutil, but it's not very secure—you will need to decide if the risk is worth it for your situation. What risk? You need to put your login password in plain text in a Keyboard Maestro macro.

If you're willing to do that, though, then this will run wdutil with sudo:

echo fubarbazbin | sudo -S wdutil etc etc

Replaced fubarbazbin with your admin account's login password. Note: I have no idea how wdutil works or if it can replace the airport command's functionality. But the above would let it be run directly in Keyboard Maestro.

-rob.

What “doesn't work anymore”?

Is the Wireless trigger not working, or the wireless tokens not working, or is the system not granting Location permissions to the Keyboard Maestro Engine?

For granting the location permissions in Keyboard Maestro 11, use the Get Location action.

Airport Utility was pulled in the 14.4.1 update.

You could use wdutil, but that'll require you to mess with your sudoers file if you want it to run from KM (rather than use @griffman's insecure echo method):

sudo wdutil info | grep "\sSSID"

...or similar.

Slower to run but no need to edit sudoers is good old system_profiler

system_profiler SPAirPortDataType | grep -A 1 "Current Network Information"

I'm no awker, so I'd just use one of the above to pull data into a variable and then use KM's text tools to process further.

1 Like

@peternlewis - I've still been using this workaround, as it was my understanding that the "wireless network" conditional was still broken in Sonoma (due to the Apple change you detailed in the original post).

I've been using the workaround that depended on a return value from the airport command. The airport command is no longer returning any value for my current wifi network. See the
attached screenshot for my quick test of the "wireless network" conditional and the implemented workaround that is no longer working as a workaround.

CleanShot 2024-04-18 at 07.46.52
CleanShot 2024-04-18 at 07.50.11

@Nige_S A quick command line run does seem to show that your suggestion works! system_profiler returned the wireless network information without sudo.

Does anyone want to take a stab at doing the awk equivalent of the original workaround?

Can you post the output of your command (when run in Terminal) here so we can see what it is you're seeing, and what it is you want to get out of it?

-rob.

That is in my original post. The work around I was using (what I was expecting) is in @peternlewis original post.

Sorry if I wasn't clear: I'm wondering what you're trying to capture out of system_profiler's output. I don't see that anywhere in your posts. When I ran the command on my machine, the word "SSID" isn't in the filtered output. You can find it in the raw source, but not with any useful info like network name.

As I don't need or use this workaround, I'm trying to determine what it is you need to get out of the command: Are you just trying to extract the network name? Something else?

-rob.

Problem is that, unlike with the original work round, we aren't getting a single line with which we can use field delimiters to extract a single "thing". You might be able to do this with awk -- but it's well beyond me!

If you really want to process down to an SSID name in the shell, this will do it most of the time:

system_profiler SPAirPortDataType | grep -A 1 "Current Network Information" | grep -E '^ {12}[^ ]' | grep -Eo '[^ :][^:]*'

I say most of the time because this uses the 12 spaces before and : after to split out the name -- but AFAIK there's nothing in the standards to say you can't start a name with a space character or include a : within it.

Most of the time you'll know the names of the networks you want to adjust for, which is why I'm thinking it might be easier to grab the whole out and then test that for a match using KM actions -- it would certainly make maintenance easier!

My bad @griffman - wasnt sure what you were replying to.

Check out this command:

It returns the Wifi Network name... I'd like to replace the airport command in the attached image with system_profiler and store the result (after updating the awk) in the WifiNetwork variable

CleanShot 2024-04-18 at 07.50.11

Oh, OK. I totally missed what you were trying to get to :). I think networksetup is a better solution for that:

networksetup -getairportnetwork en1 | sed 's/.*Network: //'

That should return the name of your wifi network, and quite quickly. Note: This assumes your wireless router is on en1. To find out, use this command; the network number will be after "Device:" in the output:

networksetup -listnetworkserviceorder

-rob.

For completeness -- system_profiler can spit out JSON (which I always forget because I'm useless at processing JSON!). So:

Current SSID Name.kmmacros (3.2 KB)

Image

But @griffman's right, and using networksetup is a much better method. To cover my embarrassment, here's a one-liner that will grab the "Wi-Fi" interface from the service order and use that in networksetup and, because you're keen on it, uses awk to spit out the SSID name:

networksetup -getairportnetwork $(networksetup -listnetworkserviceorder | grep -A 1 'Wi-Fi' | grep -Eo '[^ )]+)$' | tr -d ')') | awk -F ': ' '{print $2}'

A bit overkill unless you are constantly changing the service order and, obviously, won't work if you've got a third party wireless option or have somehow renamed the service...

2 Likes

Can't believe I didn't think of this earlier -- I'm using something similar on my phone!

For really easy mode, make the following Shortcut:

And use it in your macro:

image

Job done!

2 Likes

That workaround predates Keyboard Maestro 11, which has a Get Location action which should force prompting for the Location permissions, which should then result in all the Network wifi facilities (trigger, condition, etc) working.

1 Like

Thanks @peternlewis! I wasnt aware that it was now working in KM 11. I just tested it, and as you said, after authorizing location permissions, it's working again!

1 Like

Great idea, thanks for that!

Confirmed that this works! Thank you!

Thanks for the help!