Last active
June 29, 2022 10:15
-
-
Save qguv/2f83bcbea302b12f35bfeef56f33272a to your computer and use it in GitHub Desktop.
Save macOS screenshots in ~/Pictures/Screenshots/YEAR/MONTH/
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
<?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> | |
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
# 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 |
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
<?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