Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Script to turn wifi on/off

Hello,


Can someone provide a script that will simply turn on or off wifi as if using doing this manually from the menu bar?


THx!

Posted on Oct 3, 2011 3:01 PM

Reply
3 replies

Oct 3, 2011 6:01 PM in response to Barney-15E

Thanks for this. I did google and find a few others before I posted but none of them worked.


This one did work http://www.makiaea.org/post/5993587804 after I changed "en0" to "en1"


THis is working in my MBP:


-- 20110529 www.makiaea.org ref: 20110529wlx-wirelessonoff.applescript

-- wlx toggles wifi (airport wireless) power on and off

-- Tested using macbook air 3,1 , mac os 10.7 (Build 11A459e), quicksilver ß59 (3842)

-- if you are not using quicksilver to run the script, you may need to compile the script first (using applescript editor) and save as an .scpt script or as an app if you want to double–click with the mouse on an icon to run it.


-- note this assumes your wireless ethernet interface is en1

-- get the correct interface from the menu Apple|About This Mac|Network|Wi-Fi or from terminal using ifconfig -a

try

set makiaeawirelessstatus to do shell script "networksetup -getairportpower en1"

on error

display dialog "The script did not work as intended, please check the networksetup command (in terminal) works on your system. It has been tested on mac os 10.7 (Build 11A459e). Other versions of mac os may not have this command available. Please open the applescript in applescript editor for more details." buttons {"kthxbai"}

end try


if makiaeawirelessstatus is "Wi-Fi Power (en1): On" then

do shell script "networksetup -setairportpower en1 off"

else if makiaeawirelessstatus is "Wi-Fi Power (en1): Off" then

do shell script "networksetup -setairportpower en1 on"

else

display dialog "The script did not work as intended, please check your wireless connection is specified correctly. The default in this script is en1 (please open the applescript in applescript editor for more details)" buttons {"kthxbai"}

end if


THx

Script to turn wifi on/off

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.