Skip to content

Instantly share code, notes, and snippets.

@jlafitte
Last active June 19, 2018 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlafitte/b0a6e2bcd5edb2f80369 to your computer and use it in GitHub Desktop.
Save jlafitte/b0a6e2bcd5edb2f80369 to your computer and use it in GitHub Desktop.
OS X Screenshot Script
<?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>me.screenshot</string>
<key>ProgramArguments</key>
<array>
<string>/Users/john/scripts/screenshot.sh</string>
</array>
<key>StartInterval</key>
<integer>60</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#! /bin/bash
idleTime=60
format=jpg
destination=$HOME/Desktop/Screenshots/
if [ $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)) -lt $idleTime ]; then
echo "taking screenshot"
foldername=""`eval date +%Y-%m-%d`""
mkdir -p "$destination$foldername"
filename1="$destination/$foldername/image_01_"`eval date +%Y-%m-%d-%H-%M-%S`".$format"
# filename2="$destination/$foldername/image_02_"`eval date +%Y-%m-%d-%H-%M-%S`".$format"
screencapture -x -r -m -o -t $format "$filename1"
else
echo "idle - no screenshot"
fi
@jlafitte
Copy link
Author

jlafitte commented Feb 3, 2015

  • Add the plist file to /Library/LaunchAgents/
  • Put the sh file in ~/scripts
  • Then run launchctl load -w /Library/LaunchAgents/me.screenshot.plist

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