"tags" attribute is blank when used to rename a file

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

Moderator: Mr_Noodle

I have a rule that checks, among other things, that "Tags" is not blank. Upon a match, the file is renamed. Part of the rename includes the "tags" attribute. The rule fires, and the rename is executed, but the part of the name that should be the tag is missing.

I created this rule quite some time ago, and it has worked fine until now. The last time it ran successfully was in April. I tested this every way I can think of, but the "tags" attribute is always blank.
roddyt
 
Posts: 11
Joined: Thu Mar 27, 2014 7:47 pm

What version of Hazel and macOS are you running?
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr_Noodle wrote:What version of Hazel and macOS are you running?


Monterey 12.4 and Hazel 5.1
roddyt
 
Posts: 11
Joined: Thu Mar 27, 2014 7:47 pm

Try updating to 5.1.4. Note that the in-app updater may be broken in which case I suggest downloading and installing the update manually.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Version 5.1.4 did not correct the issue. The tag is still not included in the file name.
roddyt
 
Posts: 11
Joined: Thu Mar 27, 2014 7:47 pm

When you preview the file, check the tags attribute to see what value Hazel sees (see the manual for how to do this).

Also, are you using the Tags attribute built in to Hazel or the one you get by browsing "Other attributes"?
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Here is the rule with the preview. The tag contains the expected value. Where you ask if I am using the Tags attribute, I assume you mean in the condition (which you can see I do), as there is no specific Tag attribute on the action side that I can see.

Image

This is the result

Image

Here are the last four files processed by this rule, which shows what I expect to see. As you see by the date, this rule worked fine as of April 19. The rule hasn't been edited at all since then, but now the tag element is blank for some reason.

Image
roddyt
 
Posts: 11
Joined: Thu Mar 27, 2014 7:47 pm

I'm unable to replicate the issue here. Is the file just landing in that folder? If so, try a delay by using "Date added is not in the last X minutes" and see if that changes anything.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

No, a delay didn't work. Normally, the file is sent there by a move action from another folder, but in testing, I have been dropping the file in manually. Either way, the result is the same.

I even tried adding a tag before the rename to see what would happen. It is still blank.

Image

Finally, I loaded Hazel on a spare laptop I have, created a simple rule that tested that if "Tags not blank", then rename the file to a random name that included the tags attribute. I fed it a file with a tag assigned, and same result, the file was renamed, but the tag was not included.

I thought it might be something with my system, but now that does not look like the case given the same issue on two systems. But if you can't replicate it, I'll let it go at that. The only thing missing from the rename is the tag, and since each group of files processed each time have the same tag, I can easily rename them manually in the Finder afterward to add the tag.
roddyt
 
Posts: 11
Joined: Thu Mar 27, 2014 7:47 pm

Was the tag added successfully even if the file was not renamed properly?
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Yes. The file had a single tag to start with (to satisfy the condition). I added a different tag. I checked in the Finder and both tags are there.
roddyt
 
Posts: 11
Joined: Thu Mar 27, 2014 7:47 pm

I am having a similar problem. I have a file with multiple tags and I want to pass all of the tags into the AppleScript.

This is the first time I have attempted to pass attributes to an AppleScript.

I am unable to upload pictures (no longer an option?) and have no shared cloud storage where I can host screenshots. So I will attempt to describe what I have implemented in Hazel.
I have two conditions and "all" must be met:
- Tags is not blank
- Tags contain match to an attribute I have defined with the name Tags and it matches "Characters".
The action:
Run AppleScript UseTagsToFile.scpt and my Tags attribute has been added as an attributes imported into the script.
Nothing is being output at this point from the script.

Hazel's preview shows that it sees all three tags applied to my test file and it is creating a single custom attribute using the first of the three tags. I'll figure out how to get a variable number of tags later.

My AppleScript (an external file)
Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

use CTlib : script "CTsLibraries.scpt"

property WriteDebugLog : true
property taggedFileLogPath : "/Users/chip/Library/Logs/CTScriptsLogs/TaggedFileLogs.log"

property theFileAlias : alias ("/Users/chip/Downloads/Test/REPORT.pdf" as POSIX file)
property attributeList : {"#Consulting", "Searchable", ":SecState"}
set theResult to hazelProcessFile(theFileAlias, attributeList)

on hazelProcessFile(theFile, inputAttributes)
   --   set logFileNameSTR to "HazelScripts.log"
   set theFileString to (theFile as string)
   if (WriteDebugLog) then my log_event(taggedFileLogPath, "The file path is " & (theFile as string))
   set itemNumber to 0
   set tags to item 1 of inputAttributes
   set tags to item 1 of inputAttributes
   if (WriteDebugLog) then my log_event(taggedFileLogPath, "The tags are " & tags)
   
   --set theAttributes to inputAttributes as string
   return {hazelStop:true}


When the script runs the log file contains something like the following:

2022_08_03 15:07:49-0600 The file path is Macintosh HD:Users:chip:Downloads:Test:REPORT.pdf
2022_08_03 15:07:50-0600 The tags are missing value

So for some reason the Custom Attribute is not being passed into AppleScript.

I'll keep playing with it.
AgingKeeper
 
Posts: 5
Joined: Fri Mar 28, 2014 9:59 am

So I changed the rule I use in Hazel and it seems to work now. Not certain why the changes altered the behavior but they have.
So here is what I did with the conditions:
Unrelated to the aforementioned issues I added 4 tests that are required to reject files with the kinds of Folder, Disk Image, Alias, ZIP archive.
I then created two conditional matches "any" of which must be satisfied. I have one match that looks specifically for tags that start with a # and make that the PrimaryTag and then I look for tags that start with a ":" and make that the "SecondaryTag".

As I said this does work correctly now. I do not yet understand why.
AgingKeeper
 
Posts: 5
Joined: Fri Mar 28, 2014 9:59 am

Use imgur.com to host images. I'd need to see the full rule to get a better sense of what's going on.
Mr_Noodle
Site Admin
 
Posts: 11250
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Mr. Noodle - I am not sure what I did that caused things to change but, as I posted last evening (my time) things appears to be working now. So if you do not have time for this I understand!

At a minimum for other readers I'll include screenshots to show what was not working and what is now working.

My first rule implementation I was using is
Image

This rule being previewed
Image

(AppleScript provided previously)

The results in my log file
Image

The file I have Hazel Operating on at the time of the results above.
Image

As I mentioned I modified the rule and it mysteriously (meaning I have no idea why :shock: ) has started working. The new rule is
Image

and the Applescript was tweaked too to write out the two tags I am interested in.
Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

use CTlib : script "CTsLibraries.scpt"

property WriteDebugLog : true
property taggedFileLogPath : "/Users/chip/Library/Logs/CTScriptsLogs/TaggedFileLogs.log"

--property theFileAlias : alias ("/Users/chip/Downloads/Test/REPORT.pdf" as POSIX file)
--property attributeList : {"#Consulting", "Searchable", ":SecState"}
--set theResult to hazelProcessFile(theFileAlias, attributeList)

on hazelProcessFile(theFile, inputAttributes)
   --   set logFileNameSTR to "HazelScripts.log"
   set theFileString to (theFile as string)
   if (WriteDebugLog) then my log_event(taggedFileLogPath, "The file path is " & (theFile as string))
   set attributeClass to class of inputAttributes
   if (WriteDebugLog) then my log_event(taggedFileLogPath, "Attribute Type is " & (attributeClass as string))
   set tag1 to item 1 of inputAttributes
   if (WriteDebugLog) then my log_event(taggedFileLogPath, "Tag 1 is " & tag1)
   set tag2 to item 2 of inputAttributes
   if (WriteDebugLog) then my log_event(taggedFileLogPath, "Tag 2 is " & tag2)
   
   --set theAttributes to inputAttributes as string
   return {hazelStop:true}

end hazelProcessFile
AgingKeeper
 
Posts: 5
Joined: Fri Mar 28, 2014 9:59 am

Next

Return to Support