Switching WiFi On and Off

[Edited due to no shebang line in the script.]

Brett hasn’t given a real toggle; he’s just given the pieces to build one.

Try this:

#!/usr/bin/env bash

device=$(networksetup -listallhardwareports | grep -E '(Wi-Fi|AirPort)' -A 1 | grep -o en.)
[[ "$(networksetup -getairportpower $device)" == *On ]] && v=off || v=on
networksetup -setairportpower $device $v

Run it from an Execute Shell Script action in KM.


Best Regards,
Chris

2 Likes