Last active
March 24, 2022 20:34
-
-
Save ironprice91/275fbe18069faec47442 to your computer and use it in GitHub Desktop.
shell script for moving screenshots to archived screenshot dir
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
| #!/bin/bash | |
| DEFAULT_DIR="cd ~/Desktop/" | |
| SCREENSHOT_ARCHIVE_DIR="screenshot_archive" | |
| eval ${DEFAULT_DIR} | |
| if [ ! -d "$SCREENSHOT_ARCHIVE_DIR" ]; | |
| then | |
| mkdir "$SCREENSHOT_ARCHIVE_DIR" | |
| fi | |
| find . -maxdepth 1 -name 'Screen*.png' -print0 | while IFS= read -r -d $'\0' line; do | |
| MOD_DATE=`stat -f "%Sm" "$line"` | |
| DATE_DIR=`echo ${MOD_DATE} | sed -e 's/\( \).*\( \)/-/g'` | |
| if [ ! -d "$DATE_DIR" ]; | |
| then | |
| mkdir -p "${SCREENSHOT_ARCHIVE_DIR}/${DATE_DIR}" | |
| fi | |
| if [ "$DATE_DIR" = "$DATE_DIR" ]; | |
| then | |
| mv "$line" "${SCREENSHOT_ARCHIVE_DIR}/${DATE_DIR}" | |
| fi | |
| done | |
| # crontab | |
| # 00 17 * * 5 zsh ~/scripts/screenshot_cleanup.sh > /dev/null 2>&1 | |
| exit |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Crontab editing fix
http://www.thegeekstuff.com/2009/06/15-practical-crontab-examples/
http://calebthompson.io/crontab-and-vim-sitting-in-a-tree/
http://stackoverflow.com/questions/11212663/filename-last-modification-date-shell-in-script