Skip to content

Instantly share code, notes, and snippets.

@fancyremarker
Created February 17, 2012 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fancyremarker/1849998 to your computer and use it in GitHub Desktop.
Save fancyremarker/1849998 to your computer and use it in GitHub Desktop.
Set of scripts to kill Things after 5 minutes of keyboard/mouse idle
#!/bin/sh
# idlequit <application name> <timeout>
# Quits application if system has been idle for greater than timeout.
if [ $# -ne 2 ]; then
echo "Usage: idlequit <application name> <timeout>" >&2
exit 1
fi
if [ `/usr/local/bin/idletime` -gt ${2} ]; then
/usr/local/bin/pgrep ${1} > /dev/null && osascript -e "tell application \"${1}\" to quit"
fi
#!/bin/sh
echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/!{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000))
#!/bin/sh
# install.sh
cp idlequit /usr/local/bin/
chmod 755 /usr/local/bin/idlequit
cp idletime /usr/local/bin/
chmod 755 /usr/local/bin/idletime
cp local.idlequit.Things.plist ~/Library/LaunchAgents/
launchctl load -w ~/Library/LaunchAgents/local.idlequit.Things.plist
<?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>local.idlequit.Things</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/bin/idlequit</string>
<string>Things</string>
<string>240</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>StartInterval</key>
<integer>120</integer>
</dict>
</plist>
@fancyremarker
Copy link
Author

To install, clone and run sh install.sh. Can be easily edited to work for other applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment