MacOS idle time daemon

I put together a pretty simple daemon which has been compiled for and tested on MacOS 10.9.1 Mavericks. It is designed to run in the background, and at pre-set intervals check the system idle time. When that idle time meets or exceeds a pre-configured value, the daemon runs an executable. When the user moves the mouse or presses any key on the keyboard, the daemon will execute another program.

This can be incredibly useful if you would like workstations to participate in a render farm if they are idle for a certain amount of time, but remove themselves from the farm when they are being used by an artist.

To use, start by downloading the installer:

idleexecd

Or, if you would like to see how I did it, build it yourself, or use the code for something else:

idleexecd.src

Configuring the daemon involves two mandatory steps, and one optional one.

First, edit the configuration file, located at /Library/Preferences/org.n3d.idleexecd.config.plist. I originally wrote this to put machines on a Deadline render farm, so it is configured to do just that. The config file looks like this:

<?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″>
<array>
<dict>
<key>Process Name</key>
<string>DeadlineSlave</string>
<key>Run As</key>
<string>farm</string>
<key>Idle Time Launch Delay</key>
<integer>15</integer>
<key>Startup Command</key>
<string>/Applications/Thinkbox/Deadline6/DeadlineLauncher.app/Contents/MacOS/DeadlineLauncher -slave -nogui</string>
<key>Shutdown Command</key>
<string>/Applications/Thinkbox/Deadline6/DeadlineSlave.app/Contents/MacOS/DeadlineSlave -shutdown</string>
</dict>
</array>
</plist>

For process name, choose any value that is appropriate.  Run as is the user that the process will execute as. Pick any valid user besides root. The idle time launch delay is the idle time, in minutes, that the daemon will wait before it executes the startup command. The startup command will be executed when the machine has gone idle for the set amount of time. When the user moves the mouse or hits a key on the keyboard, the shutdown command will be executed. To add multiple commands to execute, simply copy and paste everything between <dict> and </dict> including the tags, and enter new command specifications.

If you wish to edit configuration parameters for the daemon, such as log file destination, edit /Library/LaunchDaemons/org.n3d.idleexecd.plist. The -p 1 command line argument is the polling interval, in seconds. Leaving this default will cause the daemon to check the idle time every second. This can be increased to 10 seconds, but when the user interacts with the machine, they may have to wait up to 10 seconds before the daemon responds to the input. The -v argument specifies verbose logging. The default location for logging is /var/log/idleexecd.log.

Last, reboot your machine for the changes to take effect.

TL;DR: Download and install idleexecd to have your OSX 10.9 workstation participate in a Deadline 6 render farm after it has been idle for 15 minutes.