WiFi Toggle Apple Script not functioning with Big Sur

Hi All, I don't tend to make changes to my BTT set up now I have it set how I like it however I've noticed after upgrading the OS to Big Sur that the apple script I have associated with toggling on/off the Wifi no longer works.

Here is the script I have:

use framework "CoreWLan"

tell the current application's CWWiFiClient's ¬

  • sharedWiFiClient()'s interface() to ¬*
  • setPower:(not powerOn()) |error|:(missing value)*

Try this:

use framework "CoreWLan"

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

(This works in BTT - not in Script Editor. In this works your script :thinking:)

Hi There, thanks for the reply.
I checked the script and this the exact same apple script I already have :confused:

Hi,
this is not the same. In your script the "not" operator is used. This occurs e.g. in the Script Debugger (not Scriptedior) an error: "1 can not be converted into type boolean". Therefore I have changed this in "(powerOn() = 0)" and it works in this and also in BTT. However, this causes in the Scriptedior the error: "true cannot be converted to type int" occurs. In this your script works fine.

Apparently the funcion "powerOn()" returns depending on the current application sometimes true/false and sometimes 0/1.

Thanks for this, I'll be honest and say I only understood about half of your reply, but I used your script and it does indeed work so thank you!

Sorry for my bad English.
Maybe this helps to understand. The script works in both:

use framework "CoreWLan"

set theInterface to current application's CWWiFiClient's sharedWiFiClient()'s interface()
set theState to theInterface's powerOn() as text
if theState is "1" or theState is "true" then
	theInterface's setPower:false |error|:(missing value)
else
	theInterface's setPower:true |error|:(missing value)
end if

However, I don't understand why the behavior is so different and 0/1 can't be converted to true/false.

Hi Dirk,

It's not your English, it's my grasp on coding!
Thank you again, I appreciate your help :slight_smile:

Matt.

1 Like