Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Save macOS screenshots in ~/Pictures/Screenshots/YEAR/MONTH/
<?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.nextcloud.screenshots.location</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>d="$HOME/Pictures/Screenshots/$(date +%Y)/$(date +%m)"; mkdir -p "$d"; defaults write com.apple.screencapture location "$d"</string>
</array>
<key>StartCalendarInterval</key>
<dict>
<key>Minute</key>
<integer>0</integer>
<key>Hour</key>
<integer>0</integer>
<key>Day</key>
<integer>1</integer>
</dict>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
# prerequisite: install python3 and grant it full disk access
# System Preferences -> Security & Privacy -> Full Disk Access -> [+] -> /usr/bin/python3
url=https://gist.githubusercontent.com/qguv/2f83bcbea302b12f35bfeef56f33272a/raw/4f14a8acec56c754387bf2f585a9546c64506b14
# unload existing agents if present
launchctl unload ~/Library/LaunchAgents/com.nextcloud.screenshots.location.plist 2>/dev/null
launchctl unload ~/Library/LaunchAgents/org.mozilla.firefox.screenshots.location.plist 2>/dev/null
# download + install new nextcloud agent
curl \
-o ~/Library/LaunchAgents/com.nextcloud.screenshots.location.plist \
$url/com.nextcloud.screenshots.location.plist
launchctl load ~/Library/LaunchAgents/com.nextcloud.screenshots.location.plist
# download + install new firefox agent
curl \
$url/org.mozilla.firefox.screenshots.location.plist \
| sed \
"s@/Users/qguv@$HOME@" \
> ~/Library/LaunchAgents/org.mozilla.firefox.screenshots.location.plist
launchctl load ~/Library/LaunchAgents/org.mozilla.firefox.screenshots.location.plist
<?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>org.mozilla.firefox.screenshots.location</string>
<key>ProgramArguments</key>
<array>
<string>/usr/bin/python3</string>
<string>-c</string>
<string>
import os
import pathlib
import shutil
downloads = pathlib.Path(os.environ['HOME']) / 'Downloads'
screenshots = pathlib.Path(os.environ['HOME']) / 'Pictures' / 'Screenshots'
for src in downloads.glob('Screenshot *'):
try:
year, month, _ = src.name.split(' ')[1].split('-')
except (KeyError, ValueError):
continue
dest = screenshots / year / month
dest.mkdir(parents=True, exist_ok=True)
print("moving", str(src), "to", str(dest))
shutil.move(str(src), str(dest))
</string>
</array>
<key>WatchPaths</key>
<array>
<string>/Users/qguv/Downloads</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment