Game development, Unity3D, Second Life, and Metaverses, man.
Lifelogging Made Easy: Automated Screenshot Capture and Private Upload Using OSX Automator
Hey You! If you like this app, write a comment and suggest how it can be improved.
In my quest to become a more effective worker and husband, I have been paying a lot of attention lately to websites like David Allen’s Getting Thing Done (for workflow management), LifeHacker (tips and tricks), and more recently Quantified Self. The latter is a gathering point for lifelogging enthusiasts.
One primary task of lifelogging is to capture data about oneself and one’s surroundings as:
detailed as possible
often as possible
easily as possible.
The first two are fairly easy for me, with dual backgrounds in physiographic research (trained to make detailed, reliable, repeatable, meaningful statistical measures) and web application development (heck, we can log interesting things as often as we want with cellular, PHP, MySQL, and statistical software like R/SPSS/SAS). The third– ease of capturing data– is very difficult to get right for a busy guy like me.
This post details my first attempt at automating screenshot capture and saving it to a private online archive. The idea is to be able to run all sorts of analyses on what I see each day through a primary lens of my life: my laptop and my mobile phone screens. With screenshots, we can run activity-by-time analyses by comparing the number of pixels that differ between successive shots. We can run color psychology analyses: is there an effect on my happiness/productivity/other quality-of-life measures based on what I see? We can run OCR on each screenshot and do a semantic content analysis at the word/phrase/sentence/paragraph/corpus levels of what I see/read all day, and how that evolves over time, and how it correlates to other aspects of my life.
And so forth.
But it must be effortless– if any of the logging requires intervention from me, it just won’t work. I am too busy to mess with lifelogging on a continuous basis. Luckily, OSX provides a handy little tool called Automator that you can use to, well, automate routine tasks like taking a screenshot, giving it a meaningful timestamp name, and uploading it to an archive for safekeeping and later analyses. The bonus to this approach is that it won’t suck up hard drive space on my machine. Each screenshot is only about 300K (as a .png image file), but that adds up fast if you’re taking one every second, minute, or even hour.
Here’s how I automate lifelogging screenshots:
Have a web host with unlimited disk storage and bandwidth. I use DreamHost (yep, that’s a referral link). They’re super inexpensive these days.
Open Automator. It looks like this in OSX Mountain Lion:
Choose the Application type of document. That way, you can set it to run in the background whenever your computer starts.
Add a Pause action to the empty right hand pane. I start with a pause to give the computer time to finish starting up and me time to log onto my usual home work or mobile network. The pause also allows a sensible interval between screenshots so that I’m not uploading gigs of images everyday (that’s not necessary with long term statistical analyses) or creating images faster than I can upload them.
Now, add a Run Shell Script action and fill it in with the following text, like so:
The first line just sets up what shell we’re using to run this script (bash, in this case. Linux folks, don’t hate! 🙂 )
The tmp=$… line asks our little app to create a temporary .png file with a unique filename.
The screencapture line actually takes the shot (silently, using the -x) and writes it to our temporary image file
The Filename=… line designates that we want the filename for the image to be a YEAR-MONTH-DAY_HOURS:MINUTES:SECONDS.png timestamp. Very useful for later sorting and analyses.
Then we FTP into our webserver. Replace my.website.name.com with the appropriate URL to your FTP site.
Replace CreationEngine with your FTP username and replace MyTopSecretPassword with your FTP password.
We select binary transfer mode to send the image.
The cd screencaptureSubdirectory line moves us to the remote folder we have created previously to store the images (now’s a good time to make it before you run this program!). IMPORTANT: cd to a folder that is NOT web-accessible. You’re creating a profoundly personal and private log of your daily activity with this… don’t share it. Seriously.
We upload the file with the put… line.
Then we disconnect and destroy the local version of the screenshot so it doesn’t eat up our hard drive.
Then we add a Loop action to the Automator workflow:
I set it to loop 999 times automatically, without waiting for user input.
Good, now save this Automator workflow as an application. Make sure to choose file format: Application. Save it wherever you like. Now is a good time to hit the play button in Automator to verify that your shell script is successfully screenshotting, renaming, and uploading your desktop.
Now, set the application to launch whenever your computer starts. Go to the Apple Menu –> System Preferences… –> Users & Groups control panel.
Click the Login Items button at the top of the right pane to reveal a list of all the stuff that starts up when your computer does. Then click the “+” button at the bottom of the list and add your app. Above, mine is called AutomatedScreenshotUploader. Check the box to the left of your app once it is added to hide it from regular use. Apparently you’ll still see the spinning gear icon in your OSX menubar. I’m going to try to hide that later, as it is annoying.
Restart your computer to test that it works— after sufficient time has passed, you should be able to FTP into your server and see screenshots:
And, you’re done!
Note on the classic monomyth: use this app for good, never for evil.
Note on performance: On my late 2010 MacBook Pro, this eats about four and a half percent of my cpu to run in the background. Overkill? Totally. I’ll keep looking for a more efficient route.
Note on Reliability: I have no idea how well this will handle getting on/offline, VPNs, all sorts of other considerations. If you know of a way to improve this, please share with me and everyone else in the comments, below.