Please see this post for a more recent version which works in OS X 10.11 El Capitan and newer.
Do you own a Wake-on-LAN (WOL) capable NAS (network attached storage) unit? Is your computer a Mac? Want to save on your energy bill?
The consumer NAS units you can buy these days are actually small Linux computers with a software RAID and a bunch of S-ATA hard drives inside. Depending on the make and model, some NAS units consume a considerable amount of energy even in standby mode. For instance, my QNAP NAS still consumes around 25W after all disks spun down. However, once I shut my NAS down, it only consumes 1W in deep sleep mode. It just keeps its network adapter barely alive so it’s able to “hear” a Wake-on-LAN signal.
I’m using my QNAP NAS primarily for backup purposes with Time Machine and SuperDuper. I usually don’t need my NAS on power hungry standby all day and night when I’m not at my Mac. So I thought it would be nice if the NAS could be woken from deep sleep whenever I’m starting my Mac. I then could use the internal scheduler in the NAS’s configuration interface to shut it down at predefined times (i.e. shutdown at 10 p.m. on weekdays).
I found some source code for a command line Wake-on-LAN tool and created a new x86_64 binary using Apple Xcode. To automatically start this WOL command line tool at boot time I needed a new “LaunchDaemon”.
com.trick77.wol.plist LaunchDaemon configuration
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"><plist version="1.0"> <dict> <key>Label</key> <string>com.trick77.wol</string> <key>ProgramArguments</key> <array> <string>/usr/bin/naswake.sh</string> </array> <key>RunAtLoad</key> <true/> <key>ExitTimeOut</key> <integer>60</integer> </dict> </plist>
naswake.sh
#!/bin/sh . /etc/rc.common CheckForNetwork while [ "${NETWORKUP}" != "-YES-" ] do sleep 5 NETWORKUP= CheckForNetwork done sleep 5 /usr/bin/wol 00:02:9C:C5:AD:31 #<-- Edit NAS MAC address here
What does naswake.sh do? It checks every 5 seconds if the network is up and once it is, it sends a Wake-on-LAN packet to the MAC-address indicated. The LaunchDaemon will spawn a new thread for naswake.sh so your Mac’s boot time won’t increase. If after 60 seconds still no network is up, naswake.sh will be terminated automatically by launchd.
Download and install NASwake
Check the download area on this site for an installable NASwake.pkg which contains all the files needed.
You have to edit naswake.sh and change the MAC-address to the address the LAN-adapter of your WOL-capable NAS is using. Usually, the MAC address can be found somewhere in the admin interface of the NAS unit. Once you installed the .pkg open Terminal and enter
sudo nano /usr/bin/naswake.sh
to edit the MAC address. Save and exit with ctrl-x.
How to uninstall NASwake
If you want to uninstall NASwake just open Terminal and enter
sudo rm /usr/bin/naswake.sh && sudo rm /usr/bin/wol && sudo rm /Library/LaunchDaemons/com.trick77.wol.plist
Troubleshooting
- Did you enable Wake-on-LAN on your NAS?
- Did you edit naswake.sh to insert the correct MAC address of your NAS as indicated above?
- Does WOL work if you use WakeOnLan for Mac?
- Are you using Mac OS X 10.6.5 or later?
- Do you see any error messages in /var/log/system.log related to the com.trick77.wol LaunchDaemon?
Other WOL software for the Mac
Check out Readpixel’s great WakeOnLan software for the Mac. It discovers all other computers in your LAN, and enables you to wake them up by clicking a button. If your remote computer is a Mac you can put it asleep too.
Thanks
Kudos go out to Jeff Kelley for providing a simple shell script to check the network state in a LaunchDaemon, Fred N. van Kempen and G. Knauf for the Wake-on-LAN tool source code.
I think that El Capitan wiped the /usr/bin directory clean (of all third-party items). Also, /Library/LaunchAgents used to carry the trick77 plist and that, too, is missing.
I’m pretty sure that reinstalling the .pkg should fix that. It’s just that you need your .sh script from a backup source (e.g. Time Machine) to reapply your NAS IP and everything.
Does the latest version also runs on El Capitan? I just did a clean install and I miss it to get my NAS from standby to power via shortcuts. With 10.10 Yosemite everything worked perfectly.
James, you’d have to use something like SleepWalker to call the WOL-script once your MacBook wakes from sleep:
http://www.bernhard-baehr.de
I’m using it to call sleep/wake scripts in a generic way using two shell-scripts, /etc/rc.wakeup and /etc/rc.sleep called from a LaunchDaemon based on SleepWalker. I think I got the instructions from here:
http://tyhoffman.com/blog/2013/09/sleepwatcher-power-event-driven-automation/
Cheers,
Jan
Wow!! awesome work!
Is there anyway this can work when your macbook resume from sleep? I have managed to get this to work when i first boot up and log on, but not when resuming from sleep
Thanks for the great work
Martin, I’ve found it here:
http://web.archive.org/web/20120701044524/http://www.readpixel.com/wakeonlan/index.html
Thanks to the Web Archive! :)
Since the readpixel website is gone, I wonder if you have the WakeOnLan widget from them?
This is an amazing hint! Thank you so much for taking the time to provide a .pkg installer.
BTW, doesn’t this merit publication in ‘MacUpdate’?
With greetings from Athens,
Xen
hello.. do you know how to auto shut down the NAS from the MAC when power failure? i have the backup power but it only send signal to the MAC
Thanks for the shout-out! A quick note: looks like you’re missing a linebreak after CheckForNetwork in naswake.sh. Otherwise, looks like a great reason to use my script.