Tips

Automatically Turn Off WiFi When Putting Your Mac To Sleep

Below is a workaround to replace the missing option to turn off the “power nap” for Macs with M1 chips. It is based on this solution, however, using different paths and the Automator app since the Launch Agent didn’t work for me.

What it does

The goal is to turn off WiFi when I put my Mac to sleep so that it won’t connect and do anything online while it is supposed to be inactive. I also added another script that turns on WiFi again after waking up my Mac. That works in most cases, but sometimes I have to re-enable it manually.

Preconditions

You will need a code editor (that saves files without formatting, a light-weight one is, for example, Atom), Homebrew and some experience with a terminal.

Instructions

1. In the terminal, install sleepwatcher with homebrew:

brew install sleepwatcher

Note: After installation you will see the installation path among the messages, something like /opt/homebrew/opt/sleepwatcher/sbin/sleepwatcher .... Write it down if it looks different.

2. With your editor, save the following lines as /Library/Scripts/sleepscript.sh

#!/bin/sh

networksetup -setairportpower Wi-Fi off

3. With your editor, save the following lines as /Library/Scripts/wakescript.sh

#!/bin/sh

networksetup -setairportpower Wi-Fi on

4. In the terminal, make both scripts executable:

chmod +x /Library/Scripts/scripts/sleepscript.sh
chmod +x /Library/Scripts/scripts/wakescript.sh

5. Open the Automator app.

6. Open the menu File > New, choose Application.

7. Add a Run Shell Script action from the list. In the box that appears on the right, choose as Shell /bin/bash.

8. Paste into the text field inside the box

/opt/homebrew/opt/sleepwatcher/sbin/sleepwatcher --sleep /Library/scripts/sleepscript.sh --wake /Library/scripts/wakescript.sh

and save (cmd-s) the application in the /Applications folder as Sleep watcher.app. The path /opt/homebrew/opt/sleepwatcher may be different on your Mac – see the note above.

9. Launch the Sleep watcher app for testing. You might have to give the requested permissions in the Privacy tab of your System Preferences. When you now put your Mac to sleep and wake it up again, you should see the WiFi reconnecting (it takes some seconds).

10. Open the System Preferences, go to Users, select your account and add the Sleep watcher app to your Login Items.

Christoph