Sometimes I end up asking these questions:
- How many hours did I spend on that project yesterday?
- What day did I work on x project?
- Where did the time go today?
I’m not the best at recording my time as I work on stuff. And I’ve never found the perfect time-logging application, anyway. So, the answers to these questions usually come from tedious review of file modification dates and emails. I can usually put together most of the pieces of the past week’s activities, but it’s a real pain in the ass, and the result is not very accurate.
The other day, I said to myself:
“Self, can’t your Mac automatically keep track of what I do in an easy-to-understand format?”
“Of course it can!” I replied. “How about something that produces a visual activity log where you can see what you were doing every 15 minutes of every day?”
“Excellent!! We’ll call him Screenwatcher.”
How? Simple: 3 steps!
- Create a folder in which to put your screenshots.
- Write a script that takes a screenshot and saves it in the aforementioned screenshots folder.
- Have the computer run the script every 15 minutes.
On Mac OS X 10.4, this involves a shell script and a plist for launchd. It’s easier than it sounds.
Step 1: Create the Folder
I created a folder in my home directory called ‘Screenwatcher.’ i.e. ~/Screenwatcher
This folder will automatically get subfolders for each day. The shell script handles that. Which brings us to…
Step 2: Create the Script
The shell script looks like this (replace “jason” with your username):
#!/bin/bash
# Change to a Screenwatcher directory in your home directory
cd /Users/jason/Screenwatcher
# Make a directory based on the date
mkdir -p `date "+%Y-%m-%d"`
# Capture
screencapture -C `date "+%Y-%m-%d"`/`date "+%H.%M"`.png
I saved this script here: ~/Library/Scripts/Shell/screenwatcher.sh
UPDATE: Don’t forget to give it execute permissions:
chmod 755 ~/Library/Scripts/Shell/screenwatcher.sh
Step 3: Create the launchd plist
Launchd is a part of OS X that runs tasks at specific times and/or intervals. Plist files tell Launchd what to run and when to run it.
The screenwatcher plist looks like this1:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.postpostmodern.screenwatcher</string>
<key>LowPriorityIO</key>
<true/>
<key>Program</key>
<string>/Users/jason/Library/Scripts/Shell/screenwatcher.sh</string>
<key>ProgramArguments</key>
<array>
<string>/Users/jason/Library/Scripts/Shell/screenwatcher.sh</string>
</array>
<key>ServiceDescription</key>
<string>Takes a picture of the screen every 15 minutes</string>
<key>StartInterval</key>
<integer>900</integer>
</dict>
</plist>
The StartInterval is in seconds. Change it to whatever you want. I track my time in 15 minute increments; so, 900 seconds does me just fine. If I had vast amounts of disk space, I might get crazy and try 300.
This plist needs to be saved in ~/Library/LaunchAgents (e.g. ~/Library/LaunchAgents/com.postpostmodern.screenwatcher.plist). If your LaunchAgents folder doesn’t exist, create it.
Placing the plist file in the LaunchAgents folder allows launchd to automatically find it when you log in. You can also manually load it via this command:
launchctl load ~/Library/LaunchAgents/com.postpostmodern.screenwatcher.plist
Get me off this crazy thing!
How do you stop it? This will unload it from launchd:
launchctl unload ~/Library/LaunchAgents/com.postpostmodern.screenwatcher.plist
And removing the plist from the LaunchAgents folder will keep it from being loaded next time you log in.
Final Notes
Now that all of this is up and running, you can focus on your work and know that your good ol’ Mac is keeping an eye on you. How do you know? You’ll hear the little shutter sound. If the shutter sound gets too annoying you can alter the shell script and add the -x flag to the screencapture command. But I like the sound. It reminds me that it’s doing its job.
I should also mention that the reason I keep my shell scripts in my ~/Library/Scripts folder is so it will show up in my Scripts Menu. That way, I can manually take a Screenwatcher screen capture whenever I want.
Finally, don’t forget to clean out your Screenwatcher folder every once in a while. The PNGs don’t take up a ton of space, but they take up enough. I don’t like to keep more than a few days. You could modify the script to handle the file deletion, but I prefer to do it manually.
UPDATE:
It has come to my attention that OS X 10.4.7 introduced a launchd/launchctl bug that causes this: “Workaround Bonjour: Unknown error: 0”. I haven’t seen this myself (some say it’s fixed on the Intel version of 10.4.8), but it has been confirmed to happen on a G4 PowerBook. Most Google results say that it doesn’t cause too much trouble. And I think it’s only when you run launchctl. I don’t think that it will happen when you restart.
- I actually didn’t write the plist file by hand. There’s an application called Launchd Editor that does it via a GUI. If you want to make more launchd plists, you might want to download it. ↑ back up there
Nov 18th, 2007 at 10:08 am Trey
About time to break out the Xcode and make this an app, don’t ya think?
Feb 8th, 2008 at 11:09 am Trey
Any changes to how this is setup in Leopard?
Oct 31st, 2008 at 6:45 am Patrick
Thank you very much for this great idea, except that your way doesn’t really work on Leopard.
Here’s the way I got it to work.
Change the shell script to:
Type this in your Terminal if you already have gone through the above tutorial:
launchctl unload ~/Library/LaunchAgents/
sudo cp launchctl unload ~/Library/LaunchAgents/ /Library/LaunchAgents/
sudo launchctl load /Library/LaunchAgents/
That worked for me. I think the problem lies in the new permission system on Leopard.
Oct 31st, 2008 at 6:56 am Patrick
Ooops, something went horribly wrong with the comment so I provide the instructions at http://gist.github.com/21292
Nov 27th, 2009 at 6:41 am Matthew
Try rescuetime