Apr 08, '08 07:30:00AM • Contributed by: finitesquid
One of the energy/disk saving features of the new base station firmware is that it will spin down attached drives if they have not been accessed in approximately 10 minutes. This is good for saving a couple of watts of power, as well as prolonging the life of a hard drive. If a drive is used as a Time Machine volume, the delay in waiting for the drive to spin up and be accessible is quite acceptable.
However, if the drive is being used as a network share for data (in my case, iTunes media and archival data), the five to ten second delay caused by spinning up is not acceptable (at least to me). And since there's no parameter to disable disk sleeping on the AirPort, I wrote a trivial program and launchd plist file to "tickle" the disk every few minutes to keep it spinning (and just that one disk - I have two other USB disks attached to that basestation that are for Time Machine, and I do want them to spin down).
So, here are the main features of TickleDisk:
- A script named TickleDisk is run every five minutes by launchd
- This script only runs when you are logged in to your account on the Mac it's installed on.
- TickleDisk checks to see if it's within a time window that I want to keep the disk spinning (e.g. between 9am and midnight). If it's outside of the time window, it just exits.
- If it is in the time window to keep spinning, it checks to see if the disk is mounted. If it's not, it just exits.
- If the disk is mounted, it then touches an invisible zero-length file at the root directory of the disk. This is enough to keep the disk spinning. And my access to the data on the disk immediate.
#!/bin/sh
dir=$1
hour=`date '+%H'`
if [ $hour -ge 1 -a $hour -le 9 ]; then
exit 0
fi
if [ -d $dir ]; then
touch "$dir/.com.timofejew.tickledisk"
fi
exit 0
After creating this file, make it executable by typing in chmod 755 ~/bin/TickleDisk (or whatever you ended up calling it) in a Terminal window. You'll notice from the script that I don't want it to "tickle" the disk between 1am and 9am (that's the 1 and 9 you see in the first if statement). Modify this time window to your needs (remember it's a 24 hour clock, from 0 to 23).
The plist file below needs to be placed in the directory ~/Library/LaunchAgents and called something like com.timofejew.TickleDiskNameDrive.plist (where DiskName is the name of the AirDisk that is meaningful to you). There are a couple of things to modify in the plist file to get this to work:
- The <string> tag in the Label section needs to be the same as the name of the plist filename.
- The first <string> tag in the ProgramArguments section needs to be the full path to the TickleDisk script.
- The second <string> tag in the ProgramArguments section is the mounted path of the AirDisk (usually something like /Volumes/NameOfAirDisk, where NameOfAirDisk is the name of the disk that you want to keep spinning.
[robg adds: I haven't tested this one. Many years ago, we ran this hint which set up a cron task to tickle a disk; this hint is a modern, more robust version of the same thing, basically.]
