Please can you check where I’m going wrong with this - I have one to turn off wifi when the ethernet cable is connected and one to do the opposite:
Turn off wifi when on ethernet
Triggered by any of the following:
Trigger iconUSB Device ‘Apple USB Ethernet Adapter’ is Attached
Will execute the following actions:
Action iconExecute AppleScript
do shell script "networksetup -setairportpower en0 off"
Display trimmed results in a window.
Macro iconTurn on wifi when unplug ethernet
Triggered by any of the following:
Trigger iconUSB Device ‘Apple USB Ethernet Adapter’ is Detached
Will execute the following actions:
Action iconExecute AppleScript
do shell script "networksetup -setairportpower en0 on"
Display trimmed results in a window.
Sorry Chris - my problem is that neither action works. When I unplug my macbook from ethernet wifi doesn’t turn on, and vice versa when I plug it back in.
Please clarify your first note specifying what I need to do to rectify the problem.
As this article mentions – you can run a shell script from an AppleScript – and you can run an AppleScript from a shell script.
But it is more efficient and easier to read IF you run just one kind of script natively (when that's possible).
Since Keyboard Maestro has an Execute a Shell Script action it is nevernecessary to run a shell script from an Execute an AppleScript action using a do shell script command.
The only time it's useful to mix and match AppleScripts and Shell Scripts is when one depends upon the output of the other.
I guess the OP won't need the solution anymore after 553 days (as Discourse just let me know), but I ran into the exact same problem and maybe others find this helpful too:
It looks like Network Cards connected to USB never really get detached. Even when you unplug them, they remain "connected" until you delete them in System Preferences / Network.
The easiest way to check for connected USB devices is the following shell command:
ioreg -p IOUSB
In my case, I am using a thunderbolt dock that also has a sound device. And that sound device gets disconnected when I unplug my Mac, so I am just using that instead.
Hey mate, i was looking at this and figured it out. I am on MacOS Catalina too, i think things slightly changed. OK, here goes and hope it helps you and others.
Go to your Apple logo on your finder and click on 'About this mac'. Click on System report (towards the bottom) of that screen and copy/write the name of your USB ethernet device like for like.
Next, go to Keyboard Maestro and enter these settings as shown on the screenshots. To do the opposite, set the airpower en0 on and the device to not attached.