Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pstoute/3a70ef24618c76e076fdd774412d19c1 to your computer and use it in GitHub Desktop.
Save pstoute/3a70ef24618c76e076fdd774412d19c1 to your computer and use it in GitHub Desktop.
PLIST to auto delete screenshots older than 60min and check every hour.
<?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.my.delete.screenshots.every.hour</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<string>find ~/Pictures/Screenshots/Screen* -mmin +60 -exec mv {} ~/.Trash \;</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>3600</integer>
<key>KeepAlive</key>
<dict>
<key>PathState</key>
<dict>
<key>~/Pictures/Screenshots</key>
<true/>
</dict>
</dict>
</dict>
</plist>
@pstoute
Copy link
Author

pstoute commented May 27, 2022

Tired of deleting all your screengrabs on your mac? Me too.

I wrote a plist file to automatically find any screenshots older than 60min and move them to the trash can automatically at the top of the hour or on wake.

To use this exact script, you'll need to do the following:

  1. Add a new directory in the "Pictures" directory in your user's directory called "Screenshots"
  2. Change the default location where screenshots are saved to your new "Screenshots" directory.
  3. Create the plist file in the "~/Library/LaunchAgents/" directory which should look like this:
    ~/Library/LaunchAgents/com.my.delete.screenshots.every.hour.plist
  4. In a terminal window type:
    launchctl load ~/Library/LaunchAgents/com.my.delete.screenshots.every.hour.plist

If you need to undo this automation for any reason you just need to unload the plist from launchctl via terminal:
launchctl unload ~/Library/LaunchAgents/com.my.delete.screenshots.every.hour.plist

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