[SOLVED] Rename Folder When New File Is Added/Deleted

Not a Hazel user, but @noisneil's screen shot suggests you can pass variables into the AppleScript. If Hazel reports which folder's change caused the workflow to run you should be able to pass that to the AppleScript to be used as a parameter in the do script -- your KM macro could then use that parameter to target the correct folder.

So you'd only need one Hazel workflow per "parent" folder (or only one if you can use multiple triggers) and a single KM macro to cope with however many folders you have.

2 Likes

You read my mind!

For Hazel to monitor folders you actually need to add them manually.
For example this folder:
~/Desktop/Test
and this folder:
~/Library/Audio

Would have to both be added. Also, the developer says it's not good practice to add a folder with too much content such as the ~/ for example.

Not sure if this makes sense, but maybe I'm not getting what you're saying, especially because I'm not that knowledgeable when it comes to scripting and all that.

@Nige_S maybe what you're saying is that the KM macro would always be the same, so just 1 instance of it, and then the work of adding new folders would only be done inside Hazel? For example if I have 50 folders to monitor, I would add 50 folders to Hazel, but only 1 KM macro. Is that what you're saying?

And the 50 folders is just assuming they are all parent folders, of course, with other folders inside.

1 Like

Exactly.

Update Folder Name with File Count (Hazel Version).kmmacros (31 KB)

Macro screenshot

Hazel Screenshot and Code

tell application "Keyboard Maestro Engine"

do script "<Macro Name or UUID>" with parameter theFile

end tell
3 Likes

So just to make sure I understand everything:
1 - The macro you just shared will stay untouched
2 - When I want to monitor a different parent folder, I add it to hazel and I can just copy the new rule you just shared. The UUID will always be the same on all rules, regardless of the folder added to Hazel, because KM will figure out where to apply those changes.

Right?

1 Like

Yes, that's right. :+1:t3:

1 Like

I'm getting this (those are 2 folders inside the parent folder called test):
image

This is what I have inside Hazel:

I copied the UUID from the new macro you shared

@noisneil never mind... it's working now. I don't know if it was a glitch or not...

@noisneil it's working on the original folder, but when I try to add a new folder, nothing changes. I even clicked "Run Rules Now" inside Hazel, but it's not working.

Did it start working after you hit Save in Hazel by any chance?

What do you mean? It doesn't make logical sense that it would only work for one specific folder... Screenshots would help.

No. Same thing.

Yes, no logical sense at all, but that's what's happening.

Screenshots... This is what I have on both folders inside Hazel:

I didn't change anything inside your macro.

These are the folders inside Hazel:
image

These are the folders in Finder:
image

I'm no AppleScript expert, but... I wonder if it makes a difference that there seems to be a line break before "parameter"? I'm clutching at straws to be honest.

I just checked and multiple folders work ok for me. :man_shrugging:t2:

That's not a real line break. It's just the text being wrapped, because of the available space.
Also, if that was the issue, it wouldn't work with none of the folders, because it's an exact copy on both rules. It's weird indeed...

2 Likes