Skip to content

Instantly share code, notes, and snippets.

@samwightt
Created May 22, 2018 21:52
Show Gist options
  • Save samwightt/339ebfe76bdb39cf170be632d81d0357 to your computer and use it in GitHub Desktop.
Save samwightt/339ebfe76bdb39cf170be632d81d0357 to your computer and use it in GitHub Desktop.
Script to organize files based on their creation dates in Hazel. Can be wrapped in a for loop to target multiple files outside of Hazel.
# $1 is the path to the file that you want to move. This is automatically set in Hazel on Mac.
# If you're not using this with Hazel, uncomment the line below and set the file's direct path.
# 1=file/path/here
# If you're using this with a different type other than pdfs, change all occurences of *.pdf in the file to *.ext,
# where .ext is the extension of the file type you are targeting.
# Variable to store directory structure.
date=`date -r "$1" +%Y/%b/%d`
# Uncomment to set parent directory to copy to:
# cd directory/to/move/to
# Make nested folder structure only if it needs to be made.
mkdir -p "$date"
# Get the number of pdfs in the folder.
count=`find ${date} -name "*.pdf" | wc -l`
count_trimmed="$(echo -e "${count}" | tr -d '[:space:]')"
# Move file to folder.
mv "$1" "${date}/${count_trimmed}.pdf"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment