Skip to content

Instantly share code, notes, and snippets.

@valter-silva-au
Created November 18, 2021 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valter-silva-au/6c74fd13d281a862b15559b227b2974f to your computer and use it in GitHub Desktop.
Save valter-silva-au/6c74fd13d281a862b15559b227b2974f to your computer and use it in GitHub Desktop.
Create a daily directory to keep downloads organized
#!/usr/bin/env bash
set -eu
echo "=== START: ORGANIZE FILES AND DIRECTORIES $(date)"
YEAR=$(date "+%Y")
MONTH=$(date "+%m")
DAY=$(date "+%d")
TODAY_DIR="${HOME}/Downloads/${YEAR}/${MONTH}/${DAY}"
function create_today_download_dir(){
echo "START: create_today_download_dir"
echo "Creating TODAY_DIR: ${TODAY_DIR}"
# Create only if directory doesn't exists
mkdir -p "${TODAY_DIR}"
unlink "${HOME}/Today"
ln -s "${TODAY_DIR}" "${HOME}/Today"
echo "END: create_today_download_dir"
}
function update_finder_bookmark(){
echo "START: update_finder_bookmark"
# brew cask install mysides
# https://superuser.com/a/1484861
/usr/local/bin/mysides remove Today || true
/usr/local/bin/mysides add Today "file://${HOME}/Today"
echo "END: update_finder_bookmark"
}
function update_screen_capture_output_dir(){
echo "START: update_screen_capture_output_dir"
# store screenshots at the download directory as well
defaults write com.apple.screencapture location "${TODAY_DIR}"
echo "END: update_screen_capture_output_dir"
}
# requirement: https://apple.stackexchange.com/a/378558
function organize_downloaded_files(){
echo "START: organize_downloaded_files"
find "${HOME}/Downloads" -type f -maxdepth 1 -exec mv '{}' "${TODAY_DIR}" \;
# don't remove empty directories as we need them
echo "END: organize_downloaded_files"
}
create_today_download_dir
update_finder_bookmark
update_screen_capture_output_dir
organize_downloaded_files
echo "=== END: ORGANIZE FILES AND DIRECTORIES $(date)"
# add to your crontab the following
# */5 * * * * daily-downloads.sh >> /tmp/daily-downloads.sh.log
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment