Page 1 of 1

Help with a script

PostPosted: Fri Feb 14, 2020 2:30 pm
by fabio68usa
I have been using Hazel in a very simple way and just recently discovered how powerful and useful it is, I am definitely not educated and knowledgeable enough to write the script on my own but found on this wonderful forum something I could use. My goal is to set the creation date of the file based on the date contained in the its name, unfortunately I have been bending my file name convention to make the script I found work and have the file creation date work. Needless to say that my attempt to modify the script for my file miserably failed.

My current files structure is the follow YYYY-MM-DD_Description_Type.pdf, the below script is for a file with the follow structure, YYYY-MM-DD--Description.pdf

Code: Select all
Shell /bin/bash
# Take filename, YYYY-MM-DD--New Name.pdf and
# - adjust the creation date using /usr/bin/setfile -d
# --------------------------------------------------------------------------
# -- Commented Out --
# - adjust the modification date using /usr/bin/touch
# - rename the file to New Name.pdf using /bin/mv
# --------------------------------------------------------------------------

filename_without_path=$(basename "$1")
extension="${filename_without_path##*.}"
filename_without_extension_or_path="${filename_without_path%.*}"

YYYY=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $1}')
MM=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $2}')
DD=$(echo "$filename_without_extension_or_path" | awk -F "-" '{print $3}')
NNAME=$(echo "$filename_without_extension_or_path" | awk -F "--" '{print $4}')

# Change creation date
/usr/bin/setfile -d "$MM/$DD/$YYYY" "$1"
# --------------------------------------------------


Can someone point me in the right direction so I can get the script change to accommodate my file name structure? Any help on this matter is highly appreciated. TIA

Re: Help with a script

PostPosted: Tue Feb 18, 2020 11:55 am
by Mr_Noodle
I think you need to replace the "--" with "_". There may be more but that should be done at least.

Re: Help with a script

PostPosted: Wed Feb 19, 2020 4:58 pm
by fabio68usa
Mr_Noodle wrote:I think you need to replace the "--" with "_". There may be more but that should be done at least.


I have already tried that route and it is not working, also when it does, based on some combination of changes, the date is completely wrong, that's why I have been scratching my head for quite sometime!!!! :D

Re: Help with a script

PostPosted: Thu Feb 20, 2020 12:00 pm
by Mr_Noodle
Turn on debug mode as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

From there, you'll need to debug the script by printing out ("echo") different values in the script.

Re: Help with a script

PostPosted: Sat Feb 22, 2020 11:53 pm
by fabio68usa
Mr_Noodle wrote:Turn on debug mode as described here: https://www.noodlesoft.com/kb/hazel-debug-mode/

From there, you'll need to debug the script by printing out ("echo") different values in the script.



Thank you kindly for the tip!!!!