Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is it possible to have a bash script that toggle my wifi on and off? I am using lion (10.7.2).

share|improve this question
add comment

3 Answers 3

Assuming your hardware is somewhat similar to mine:

networksetup -setairportpower en1 on
networksetup -setairportpower en1 off

You can run networksetup -listallhardwareports to find the device (en1) of your Wi-Fi in case it's different.

To toggle put something like the following lines into a script or shell function:

[[ "$(networksetup -getairportpower en1)" == *On ]] && v=off || v=on
networksetup -setairportpower en1 $v
share|improve this answer
add comment
#!/bin/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

The port name is Wi-Fi on 10.7 and AirPort on 10.6. The device name can be at least en0, en1, or en2 depending on your setup.

share|improve this answer
add comment

Head over to this page. A guy by the name of heatxsink made a pretty handy script that will toggle your wifi on or off depending on the status of your ethernet connection.

You can add your own growl notifications pretty easily if you want. Also make sure to follow every step precisely as the script relies on filenames and locations of the files.

Other options: You can try out ControlPlane. It seems promising to fill your need for automation.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.