MacOS – OSX Launch Daemon for Periodic Screenshots

launchdmacosscreen capture

I'm trying to figure out how to create a daemon that will take screenshots every 5 minutes on OSX.

The daemon with launchctl seems to run under a separate session so the screenshots I'm getting right now are just of my blank home screen rather than my actual current session screen.

Currently I have a screencapture script:

#!/bin/bash

screencapture ~/Desktop/$(date +%y%m%d%H%M%S).png

And a plist file:

<?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>com.startup</string>
                <key>Program</key>
                <string>path_to_script/screenshots.sh</string>
                <key>StartInterval</key>
                <integer>15</integer>
        </dict>
</plist>

Best Answer

In the comments to the question you say "But just want it to track what I'm spending my time doing".

Interpreting your underlying question as being how to track application usage, I will risk being downvoted for not answering your question as in its title.

I think that a large collection of screenshots is not the best way to track what you are doing. Certainly further analysis will be complex.

To track application usage, I use Keyboard Maestro with a one action macro.

enter image description here

This creates a CSV file with three fields: Date, Time and Application name.

That will provide application usage in a form which is amenable to further analysis.