Page 1 of 1

Hazel Automation

PostPosted: Wed Nov 19, 2025 12:47 pm
by StirCwazy
First time poster, new user to Hazel, so be gentle. :P

I'm attempting to automate a process I've been doing manually for some time and have ran into a point I can't quite figure out. Here's an outline of the scenario, please excuse how generic I am being

Download file from Designer 1 or Designer 2 on thangs.com (3D model files)
Hazel processes the file(s) based on the following.
Extension is ZIP
Source URL/Address is from domain thangs.com
If any of the following conditions are met for the current file or folder
-Name contains Prop Kit

What I want to take place is the following.
The file is downloaded, Hazel evaluates the file and it is moved to another folder based on the designer. Simple, I've got several other rules setup using the above process, minus the Name contains varies depending on the type of model. Where it gets tricky is this.

Designer 1 uses Prop Kit in the filename, and so does Designer 2. In looking at the preview of the rule, selecting a file from each of the designers, they both match. The Source URL/Address, there's no decernable way to tell which is which as it's coming from hosted storage with google. There's no reference to the designer, just random (to me) bit of information that are different from file to file, even when it's from the same developer.

So I can't figure out how to have Hazel setup so that I can have Designer 1 go to Folder 1 and Designer 2 go to Folder 2 since they share the same Source URL/Address.

I've tried using an AppleScript prompt for which Designer it is so the file could be tagged and was planning on adding another rule that moves the file based on the tag. I couldn't get that to work, it's all above my head and had used AI to help create the script.

So, any thoughts on how I can make this work?

Re: Hazel Automation

PostPosted: Thu Nov 20, 2025 10:42 am
by Mr_Noodle
Where is this designer info stored?

Re: Hazel Automation

PostPosted: Thu Nov 20, 2025 3:12 pm
by StirCwazy
Mr_Noodle wrote:Where is this designer info stored?


I've looked at the metadata of the files and there's nothing that indicates directly where it came from unfortunately. Other than that, I'm not 100% sure what you're asking for specifically, sorry.

Re: Hazel Automation

PostPosted: Fri Nov 21, 2025 9:41 am
by Mr_Noodle
I have no idea how you are able to determine which designer is associated with each file. It has to come from somewhere and without that knowledge, I can't really advise on how to proceed.

Re: Hazel Automation

PostPosted: Fri Nov 21, 2025 1:52 pm
by StirCwazy
Mr_Noodle wrote:I have no idea how you are able to determine which designer is associated with each file. It has to come from somewhere and without that knowledge, I can't really advise on how to proceed.


Long story short, I figured out a way to make this work.

What I ended up doing is utilizing the Microsoft Edge browser download history database located at /Users/InsertName/Library/Application Support/Microsoft Edge/Default/History named History. It's a sqlite database that stores information about downloads and such.

I have a rule that monitors the Downloads folder that does the following.

Conditions:
If all of the following conditions are met:
-Extension is zip
-Source URL/Address is from domain thangs.com
--If any of the following conditions are met for the current file or folder:
---Name contains Prop Kit

Actions:
-Run shell script, below. It copies the Edge browser history file, locates the table with the download history and matches the file to the URL it was downloaded from. If it is from the Designer1 URL, it sets a Finder Comment with Designer1/, if from Designer2 URL sets a Finder Comment with Designer2.

Code: Select all
#!/bin/bash
set -x
exec >> /tmp/hazel_debug.log 2>&1

FILE="$1"
sleep 5   # wait a moment so the file isn't "busy"

EDGE_DB="/Users/insertname/Library/Application Support/Microsoft Edge/Default/History"
TMP_DB="/tmp/edge_history.sqlite"

# Copy DB to avoid lock
cp "$EDGE_DB" "$TMP_DB"

# Escape path for SQL
ESC_PATH=$(printf "%s" "$FILE" | sed "s/'/''/g")

# Query for tab_url (designer page)
TAB_URL=$(/usr/bin/sqlite3 "$TMP_DB" "
SELECT tab_url
FROM downloads
WHERE current_path = '$ESC_PATH' OR target_path = '$ESC_PATH'
ORDER BY start_time DESC
LIMIT 1;
")

CREATOR=""
if [[ "$TAB_URL" == *"thangs.com/designer/Designer1"* ]]; then
  CREATOR="Designer1"
elif [[ "$TAB_URL" == *"thangs.com/designer/Designer2"* ]]; then
  CREATOR="Designer2"
fi

if [ -n "$CREATOR" ]; then
  # Set Finder comment to just the creator name
  osascript <<EOF
  tell application "Finder"
    set f to (POSIX file "$FILE") as alias
    set comment of f to "$CREATOR"
    try
      set existingTags to the tags of f
      set tags of f to existingTags & {"$CREATOR"}
    end try
  end tell
EOF

  # Store full designer URL in extended attribute for traceability
  xattr -w com.workflow.designerURL "$TAB_URL" "$FILE"
else
  echo "No matching designer for $TAB_URL" >> /tmp/hazel_debug.log
fi

-Continue matching rules

Then I have two rules that follow that do essentially the same thing, so here's an example of one of them.

If all of the following conditions are met
-Extension is zip
-Source URL/Address is from domain thangs.com
--If all of the following conditions are met for the current file or folder
---Name contains Prop Kit
---Spotlight comment is Designer1

Then it does this
-Move to folder Designer1
-Sort into subfolder with pattern Prop Kits

I'm almost certain this is a long way around something that Hazel probably does by default, or can do easier, but, it worked. :P

Re: Hazel Automation

PostPosted: Mon Nov 24, 2025 11:05 am
by Mr_Noodle
Ok, so it's in the URL. If you use Safari to download the file, that should be available in the Source URL/Address attribute which you can match against.

Re: Hazel Automation

PostPosted: Tue Nov 25, 2025 1:03 pm
by StirCwazy
Mr_Noodle wrote:Ok, so it's in the URL. If you use Safari to download the file, that should be available in the Source URL/Address attribute which you can match against.


I'll definately look into this, appreciate the feedback.

Re: Hazel Automation

PostPosted: Tue Nov 25, 2025 1:19 pm
by StirCwazy
Mr_Noodle wrote:Ok, so it's in the URL. If you use Safari to download the file, that should be available in the Source URL/Address attribute which you can match against.


I downloaded one of the files in question using Safari and Previewed one of the rules, selecting the file, and the URL it shows is basically the same as that in Edge. There are differences, but likely due to something like a randomly generated token, or something similar.

Unless I'm not following what you mean, looks like it's basically the same, with no reference to the Designer in the URL/Address.

Re: Hazel Automation

PostPosted: Wed Nov 26, 2025 10:04 am
by Mr_Noodle
Ok, now I'm at a loss. How are you able to ascertain who the designer is for a particular file? You said you are checking where they are downloaded from but now saying that that info isn't there? I think you need to be VERY clear about how this is supposed to work. A concrete example would be helpful here.

Re: Hazel Automation

PostPosted: Sun Nov 30, 2025 7:54 am
by StirCwazy
Mr_Noodle wrote:Ok, now I'm at a loss. How are you able to ascertain who the designer is for a particular file? You said you are checking where they are downloaded from but now saying that that info isn't there? I think you need to be VERY clear about how this is supposed to work. A concrete example would be helpful here.


My apologies, I thought I explained how I was able to get it to work in my previous post but I'll run through it with specifics. The Microsoft Edge browser history file stores information on where the actual click to download takes place. It's primary usage is explained in the section regarding the script below.

Designer 1 - https://thangs.com/designer/The%20Loot%20Lab
Designer 2 - https://thangs.com/designer/The%20Kit%20Kiln

When files are downloaded and the rules in Hazel previewed against the downloaded file, Hazel shows the URL / Address like the below.

This example is from The Loot Lab, Designer 1, Huntrix Light Stick Prop Kit No AMS No Support No Glue.zip

Code: Select all
https://storage.googleapis.com/thangs-thumbnails/production/(LONG LIST OF CHARACTERS)/Huntrix_Light_Stick-_Prop_Kit_%28No_AMS%2C_No_Support%2C_No_Glue%29.zip?GoogleAccessId=api-platform%40gcp-and-physna.iam.gserviceaccount.com&Expires=(LONG LIST OF CHARACTERS)response-content-disposition=attachment%3B%20filename%3D%22Huntrix%20Light%20Stick-%20Prop%20Kit%20%20No%20AMS%20%20No%20Support%20%20No%20Glue%20.zip%22, https://thangs.com/


I imagine the items I replaced with (LONG LIST OF CHARACTERS) are generated and expire, but for my piece of mind I've removed them. The characters change, even when downloading the same file back to back but the bits I've pasted in remain the same.

In my current rules, I've done the following.

Conditions:
If all of the following conditions are met:
-Extension is zip
-Source URL/Address is from domain thangs.com
--If any of the following conditions are met for the current file or folder:
---Name contains Prop Kit

Actions:
-Run shell script, seen below. It copies the Edge browser history file, locates the table with the download history and matches the file to the URL where the actual click on Download took place. In this case, https://thangs.com/designer/The%20Loot%20Lab. It then sets a Spotlight Comment for that file to The Loot Lab.

Code: Select all
#!/bin/bash
set -x
exec >> /tmp/hazel_debug.log 2>&1

FILE="$1"
sleep 5   # wait a moment so the file isn't "busy"

EDGE_DB="/Users/stircwazy/Library/Application Support/Microsoft Edge/Default/History"
TMP_DB="/tmp/edge_history.sqlite"

# Copy DB to avoid lock
cp "$EDGE_DB" "$TMP_DB"

# Escape path for SQL
ESC_PATH=$(printf "%s" "$FILE" | sed "s/'/''/g")

# Query for tab_url (designer page)
TAB_URL=$(/usr/bin/sqlite3 "$TMP_DB" "
SELECT tab_url
FROM downloads
WHERE current_path = '$ESC_PATH' OR target_path = '$ESC_PATH'
ORDER BY start_time DESC
LIMIT 1;
")

CREATOR=""
if [[ "$TAB_URL" == *"thangs.com/designer/The%20Loot%20Lab"* ]]; then
  CREATOR="The Loot Lab"
elif [[ "$TAB_URL" == *"thangs.com/designer/The%20Kit%20Kiln"* ]]; then
  CREATOR="The Kit Kiln"
fi

if [ -n "$CREATOR" ]; then
  # Set Finder comment to just the creator name
  osascript <<EOF
  tell application "Finder"
    set f to (POSIX file "$FILE") as alias
    set comment of f to "$CREATOR"
    try
      set existingTags to the tags of f
      set tags of f to existingTags & {"$CREATOR"}
    end try
  end tell
EOF

  # Store full designer URL in extended attribute for traceability
  xattr -w com.workflow.designerURL "$TAB_URL" "$FILE"
else
  echo "No matching designer for $TAB_URL" >> /tmp/hazel_debug.log
fi


I then have 2 rules that do the following. Here is an example of the one for The Loot Lab but the other rule is the same, minus looking for a Spotlight Comment of The Kit Kiln.

If all of the following conditions are met
-Extension is zip
-Source URL/Address is from domain thangs.com
--If all of the following conditions are met for the current file or folder
---Name contains Prop Kit
---Spotlight comment is The Loot Lab

Then it does this
-Move to folder The Loot Lab
-Sort into subfolder with pattern Prop Kits

Re: Hazel Automation

PostPosted: Mon Dec 01, 2025 10:41 am
by Mr_Noodle
What's missing is how you correlate the URL to the final categorization. What part of the URL is used to determine between the designers?

Re: Hazel Automation

PostPosted: Mon Dec 01, 2025 11:20 am
by StirCwazy
Mr_Noodle wrote:What's missing is how you correlate the URL to the final categorization. What part of the URL is used to determine between the designers?


In the MS Edge History file it tracks the URL where the click took place.

For example, I download a model from https://thangs.com/designer/The%20Loot%20Lab, it sets the Spotlight Comment to The Loot Lab. In the following rule it moves the file to the correct folder.

If all of the following conditions are met
-Extension is zip
-Source URL/Address is from domain thangs.com
--If all of the following conditions are met for the current file or folder
---Name contains Prop Kit
---Spotlight comment is The Loot Lab

Then it does this
-Move to folder The Loot Lab
-Sort into subfolder with pattern Prop Kits

Re: Hazel Automation

PostPosted: Tue Dec 02, 2025 9:23 am
by Mr_Noodle
Ok, I think I'm getting it now. You are just going by the URLs in the browser history going up to the download click though I'm still unclear on what the earlier URL has that allows you to do this differentiation.

I guess my question at this point is what part isn't working/where you need help?

Re: Hazel Automation

PostPosted: Wed Dec 03, 2025 6:47 pm
by StirCwazy
Mr_Noodle wrote:Ok, I think I'm getting it now. You are just going by the URLs in the browser history going up to the download click though I'm still unclear on what the earlier URL has that allows you to do this differentiation.

I guess my question at this point is what part isn't working/where you need help?


Honestly, at this point I think I've got it working. At the start of this post I had no idea how to do it and then ended up figuring out a way to make it work along the way. =)