Testing Embedded Shell Scripts on Catalina - Hazel 4.4

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

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")

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.
Posts: 20
Joined: Sat Apr 02, 2016 7:56 pm

Seems to work for me here. Double-check that the shell is set to /bin/bash as the default is not /bin/zsh.
Site Admin
Posts: 8318
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

It worked for me as well.
Posts: 40
Joined: Tue Apr 11, 2017 7:12 pm

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.
Posts: 20
Joined: Sat Apr 02, 2016 7:56 pm

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...
Posts: 20
Joined: Sat Apr 02, 2016 7:56 pm

Return to Support