Last active
July 4, 2017 19:50
-
-
Save gsumpster/39f36315595486b24675c516160454ae to your computer and use it in GitHub Desktop.
Detects screenshots on MacOS and moves them to the trash, included launchd config too put this in ~/Library/LaunchAgents
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os import listdir, environ, rename | |
| from os.path import isfile, join | |
| from re import compile, search | |
| regex = compile("Screen Shot \d{4}-\d{2}-\d{2} at \d{1,2}.\d{2}.\d{2} [AM PM]{2}") | |
| def isScreenshot(f): | |
| return search(regex, f) | |
| files = [f for f in listdir(environ['HOME'] + '/Desktop') if isfile(join(environ['HOME'] + '/Desktop', f))] | |
| for f in files: | |
| if isScreenshot(f): | |
| rename(join(environ['HOME'] + '/Desktop', f), join(environ['HOME'] + '/.Trash', f)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!--- launchd plist: replace the ##PATH## with the path to your delete_screenshots.py, this will delete screenshots every 3 hours ---> | |
| <?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>screenshot-cleaner</string> | |
| <key>ProgramArguments</key> | |
| <array> | |
| <string>/usr/bin/python</string> | |
| <string>##PATH##</string> <!-- replace ##PATH## with your location e.g. /Users/gsumpster/delete_screenshots.py --> | |
| </array> | |
| <key>RunAtLoad</key> | |
| <true/> | |
| <key>StartInterval</key> | |
| <integer>10800</integer> <!-- replace this with your desired interval in seconds, currently 3 hours --> | |
| </dict> | |
| </plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment