Disconnect from WiFi button?

Hi,

Anyone know a way to disconnect from wifi through AppleScript or terminal command?

I can get a button to appear when connected, that turns wifi off completely when pressed. But can’t find anything on disconnecting.

This would be awesome if it could disconnect from an iPhone hotspot as well.

You should be able to disconnect using Apple script.
Also, I think there is a possibility to toggle WiFi on/off in the BTT actions, but I'm not sure about it.

I’ll have to do some more digging to find the apple script commands.

I can’t see any BTT options to turn wifi on and off. But I do currently have a TouchBar button that runs the terminal command to turn on/off

use framework "CoreWLan"

current application's CWWiFiClient's ¬
	sharedWiFiClient()'s ¬
	interface()'s disassociate()
use framework "CoreWLan"

tell the current application's CWWiFiClient's ¬
	sharedWiFiClient()'s interface() to ¬
	setPower:(not powerOn()) |error|:(missing value)
1 Like

this works great thanks

1 Like

You're welcome. :o)

The use framework "CoreWLan"-solution stopped working after I upgraded my Mac from an Intel to a M2 (don't know why). Replaced it with this which seems to do the trick:

set wifiStatus to do shell script "networksetup -getairportpower en0 | awk '{print $NF}'"
if wifiStatus = "On" then
    do shell script "networksetup -setairportpower en0 off"
else
    do shell script "networksetup -setairportpower en0 on"
end if

.. if anyone else is struggling with this too :slight_smile: