Page 1 of 1

Testing Embedded Shell Scripts on Catalina - Hazel 4.4

PostPosted: Tue Oct 29, 2019 12:53 pm
by DaveB
I downgraded my new iMac from Catalina back to Mojave after a week of testing Hazel betas. Now that 4.4 is released I'd like to avoid the time consuming process of updating to Catalina and then needing to downgrade if shell scripts are still a problem for me under 4.4.

Can anyone running 4.4 on Catalina please help me confirm the following embedded script will run? When I tested a few weeks ago, my rules all failed when they got to the shell script. I worked with Hazel support and other problems were quickly resolved, except for this one. I have to thank Noodle Support for their amazing and personal support assistance. I'm reluctant to try this all again until I can get some confidence that the shell script - changing file creation date based on date in filename function will work. I don't have an alternate Mac to test with.

Can someone running the new 4.4 on Catalina please add this shell script as an embedded script, to a rule.

The test case can match any file and then change the file creation date.

The test filename to be re-dated must be in this format: "2019-08-08--Filename to be moved.pdf"

The shell script should change the file creation date to the prepended date in the filename. In this example, the file creation date should get changed to 08/08/2019

Here's my shell script:

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"
# --------------------------------------------------
# -- Commented Out --
# Change modification date to Today/Now
# /usr/bin/touch "$1"
# Rename file
# /bin/mv "$1" "$NNAME"
# --------------------------------------------------

By the way, for anyone downgrading from Catalina to back to Mojave, be warned that the Catalina MacOS installation creates a new volume on the hard drive and moves data files there. When you restore Mojave from a backup, that Data partition remains (unless you notice it and remove the new Data partition). It caught me off guard.

Re: Testing Embedded Shell Scripts on Catalina - Hazel 4.4

PostPosted: Wed Oct 30, 2019 10:09 am
by Mr_Noodle
Seems to work for me here. Double-check that the shell is set to /bin/bash as the default is not /bin/zsh.

Re: Testing Embedded Shell Scripts on Catalina - Hazel 4.4

PostPosted: Wed Oct 30, 2019 1:56 pm
by SpinalTap
It worked for me as well.

Re: Testing Embedded Shell Scripts on Catalina - Hazel 4.4

PostPosted: Wed Oct 30, 2019 3:34 pm
by DaveB
Thank you both for confirming the shell script works. I'm ready to take another chance with the Catalina upgrade.
BTW: Catalina is my only daughter's name, so it should be charmed... We call her Catie.

Re: Testing Embedded Shell Scripts on Catalina - Hazel 4.4

PostPosted: Fri Nov 01, 2019 3:28 pm
by DaveB
I did my second upgrade from Mojave to Catalina today and tested the latest version of Hazel.
The good news is I'm back in business with my paperless workflow scanning documents into Eaglefiler via Hazel and AABBY Finereader.

Version 4.4.1[1575] no longer crashes when it gets to my shell script, Hazel gracefully pop up a message telling me the shell script failed.

Then I remembered details from an old post on this forum by ME, when I had a similar problem back when I upgraded to High Sierra.
I needed to install Xcode command line tools again. This solved the problem.

So for anyone unlucky like me, it seems that some or all shell scripts require Xcode command line tools.
The solution is simply to re-install the required xcode command line tools again.

Do that by opening up a Terminal window and typing the following…

xcode-select --install

Here's link to my original post on this issue from years ago. History repeats...
viewtopic.php?f=4&t=9329&hilit=xcode#p24786