Screenwatcher

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!

  1. Create a folder in which to put your screenshots.
  2. Write a script that takes a screenshot and saves it in the aforementioned screenshots folder.
  3. 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.


  1. 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

comment feed And the ensuing discussion…

  1. 1

    Nov 18th, 2007 at 10:08 am Trey

    About time to break out the Xcode and make this an app, don’t ya think?

  2. 2

    Feb 8th, 2008 at 11:09 am Trey

    Any changes to how this is setup in Leopard?

  3. 3

    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:

    #!/bin/bash
    # Get the PID of loginwindow.app
    PID=`ps -ax | grep loginwindow.app | grep -v grep | awk '{print $1}'`
    # Change to a Screenwatcher directory in your home directory
    cd /Users/patrick/Pictures/Screenwatcher
    # Make a directory based on the date
    mkdir -p `date "+%Y-%m-%d"`
    # Capture in the context of the loginwindow.app so it works on Leopard
    launchctl bsexec $PID screencapture -C `date "+%Y-%m-%d"`/`date "+%H.%M"`.png

    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.

  4. 4

    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

  5. 5

    Nov 27th, 2009 at 6:41 am Matthew

    Try rescuetime

Comments are closed.



Additional Resources


Tumblelog

Tumblr

Tumblr

Delicious

Delicious

Instructional

Recent Instructional Articles

Slicehost (and Linode) LAMP Cheatsheet

17.11
16

A quick list of steps I use to set up a LAMP server on Slicehost or Linode.

Terminal Tip: Prevent Creation of Mac Dot Files

07.08
2

An environment variable can prevent creation of ._filename files.

Terminal Tip: Delete Those Mac Dot Files

08.06
4

Use the find command to delete all of the ._* and .DS_Store files.

Editorial

Recent Editorial Articles

More Usable Mac: Finder Toolbar

05.12
3

I find it useful to keep a few extra items in my Finder toolbar.

No Multiple-Class Support in IE6

18.11
9

IE6 doesn’t respond to multiple class selectors.

New Skin for the Old Blogish

07.10
8

This blogish is finally back online after an extended period of http silence.

Downloadable

Recent Downloadable Articles

Gitup!

01.02
0

Gitup + Transmit = Really Simple Publishing

Leopard-Style iTerm Icon, Take 2

18.12
8

The newer, bluer version of the iTerm icon.

Leopard-Style iTerm Icon

05.12
6

An updated, Leopard-style icon for iTerm.

About This Site

About the Author

That’s me in the photo above. My current profession is web development. Therefore, it is the subject of this site.

Postpostmodern

Postpostmodern is the name of this site and my alias on most of the web. There's nothing really special about the name Postpostmodern. I studied art in college during the years after postmodernism, and nobody knew how else to classify the state of things other than silly words like postpostmodernism.

Sorta Blogish

I'd call this a blog, but I don't feel it fits the 'log' format. My goal is to publish articles on web-related topics that interest me, and while some articles may be time-sensitive, I would prefer that the organizational focus be on the categories and tags rather than chronology.

More Me

More about me can be found on the about page. Or, look me up in the usual places: