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%20LabDesigner 2 -
https://thangs.com/designer/The%20Kit%20KilnWhen 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