---
title: 'Quick Tip: Automating your Mac''s wifi power'
date: 2014-02-15 10:00
slug: quick-tip-automating-you-macs-wifi-power
categories:
- Code
tags:
- terminal
- scripting
- applescript
- productivity
- automation
- quicktip
---

This is a quick one, and many of you probably know it, but you can quickly toggle wifi on your Mac with the `networksetup` command. To turn your wifi on:

	networksetup -setairportpower en0 on

and to turn it off... you guessed it:

	networksetup -setairportpower en0 off

To make it even easier, add an alias in your shell like:

	alias wifi="networksetup -setairportpower en0"

Then you can toggle it just by typing `wifi on` or `wifi off`. Note that, depending on your network interfaces, en0 may need to be changed. You can find out what all of your network hardware addresses are with `networksetup -listallhardwareports`. Just look for the labeled "Wi-Fi."

You can also use the command in AppleScripts:

	do shell script "networksetup -setairportpower en0 on"

![](https://brettterpstra.com/uploads/2014/02/applescript-wifi.png)

I turn my MacBook Air's wifi off with [ControlPlane](http://www.controlplaneapp.com/) when I'm docked to my Thunderbolt Display (it has an ethernet line). I'm using the above script with [UnDock](https://itunes.apple.com/us/app/undock/id402359583&at=10l4tL&ct=wifitoggle) to turn it back on before I disconnect (ControlPlane would only do that _afterwards_). 

With my wifi set to a higher priority than ethernet in Network Preferences, this allows me to make fairly seamless network switches without any mousing around. [Hyper](http://brettterpstra.com/2012/12/08/a-useful-caps-lock-key/)-Escape triggers UnDock, which starts up wifi, umounts my drives and pauses Time Machine. Then, unplugging the Thunderbolt cable triggers tasks (via ControlPlane) such as hiding GeekTool in preparation for a 1440px desktop, repositioning Simplify/[Sidecar](http://brettterpstra.com/projects/sidecar/) and other handy things. Of course, it also does the whole process in reverse when I plug back in.

Just thought some other rabbit-holers might find this useful.

---

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
