Page 1 of 1

Hazel rule to "Open a Folder when a file is added"

PostPosted: Sun Jul 22, 2018 12:14 am
by Ward
I have an "on the Web" folder on my Desktop where I collect links (actually .webloc files) to specific web pages. When I drag a URL from my Safari window onto the folder, Safari automatically creates a webloc file with a filename of its choosing (often the page title).

Most of the time, I want to modify or replace Safari's automatic file name. So I've created a Keyboard Maestro keyboard shortcut to open my "on the Web" folder.

To avoid having to press the Keyboard Maestro trigger key each time, I'd like to have Hazel to respond to a new webloc file by (1) opening the "on the Web" folder and (2) selecting the new file. After several failed attempts (including a Hazel rule opening 2000+ webpages in Safari), I'm here asking for advice.

The main problem is finding a Hazel condition that detects the newly created webloc file.

If I can do that, Hazel can "Do the following to the matched file or folder:"

"Show in Finder" + "Bring to front"

-- Ward

Re: Wish: a Hazel rule to "Open a Folder when a file is add

PostPosted: Mon Jul 23, 2018 12:16 pm
by Mr_Noodle
Use "date last matched is after date added" to match newly added files. From there, you should be able to use the "Show in Finder" action.

Re: Wish: a Hazel rule to "Open a Folder when a file is add

PostPosted: Mon Jul 23, 2018 1:04 pm
by Ward
Mr_Noodle wrote:Use "date last matched is after date added" to match newly added files.

That didn't work for me, but it did encourage me to do more experimenting.

After several failures, I found setting the condition to "Any File" worked for a couple of new files. But then something triggered Hazel into opening my "on the Web" window and start selecting individual files at random, 2 to 3 per second. I was eventually able to use Activity Monitor to force quit the hazelworker process to stop this Finder activity (which was consuming my Mac, including grabbing focus from Activity Monitor).

-- Ward

Re: Wish: a Hazel rule to "Open a Folder when a file is adde

PostPosted: Tue Jul 24, 2018 11:17 am
by Mr_Noodle
"any file" isn't quite right. I did make a mistake in my earlier post though. It should be "date added is after date last matched". You can also check the sample rules as there is a rule which has a similar function.

Re: Wish: a Hazel rule to "Open a Folder when a file is adde

PostPosted: Tue Jul 24, 2018 3:21 pm
by Ward
Mr_Noodle wrote:It should be "date added is after date last matched".

"date added is after date last matched" is working, with an annoying side-effect:

When I modify a filename and close the window, it reopens several seconds later because the new filename is triggering Hazel's "date added is after date last matched" condition.

When I initially created my "Open a Folder" rule, I was looking for a Hazel condition that simply detected that a file had been added to the folder, i.e., the folder's file count had changed.

Re: Wish: a Hazel rule to "Open a Folder when a file is adde

PostPosted: Wed Jul 25, 2018 1:23 pm
by Mr_Noodle
If you are renaming it then it may very well appear as a new file. You may want to consider adding a tag to the file after opening and checking for that tag to prevent it from firing again.

Re: Wish: a Hazel rule to "Open a Folder when a file is adde

PostPosted: Thu Jul 26, 2018 10:30 am
by Ward
Mr_Noodle wrote:If you are renaming it then it may very well appear as a new file. You may want to consider adding a tag to the file after opening and checking for that tag to prevent it from firing again.

Excellent! That technique blocks reopening the window.