Create Folder on demand via PDF content, file PDF into it?

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

Moderator: Mr_Noodle

Hi all,

A workplace accounting team organizes PDF copies of Accounts Payable in a "Year:Payable To" folder structure. Currently, the filing is done via manual copies into the destination folder.

I could save labor if I could devise a workflow that operates as
-Copy PDF into a single auto-sorting folder
-PDF is analyzed for content, it seeks the name of the recipient (it's in a predictable place), then moves PDF into the paired "payable to" folder.

In my first hour of exploring Hazel, my PoC of "content contains <who it's paid to>" -> move to the folder I paired with was a home run.

Great, except that at this moment, there are 398 possible destination folders, which means 398 rules to build. Next week there will be over 400: this is both unappealing to build, and unsustainable.

The ideal rule would flow as
-Look at this consistent section of page 1 of the PDF, extract the top line
-Does a folder matching that name exist in the destination path?
--If no, then create folder
-Move PDF to the matching folder

I'm not seeing anything that looks like a way to directly get there via what Hazel offers: afaict Hazel could be the trigger for an AppleScript or shell script that would actually do the action, but in that case, isn't Folder Actions the right tool for the job?

Throwing my question out here to see if there's any power in Hazel I'm overlooking.
swy
 
Posts: 2
Joined: Thu May 22, 2025 1:40 pm

Look up list item attributes in the manual. Using those, you can have one rule to do all that. Also note that the Sort into subfolder action will create folders as needed.
Mr_Noodle
Site Admin
 
Posts: 11888
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for the reply, Mr Noodle. I've reviewed https://www.noodlesoft.com/manual/hazel ... ttributes/ , and my takeaway is that I'd have to have a list item of every possible payee defined in here. Is that accurate?

Since my post request, ChatGPT and I took a shot at this together, and have made a Folder Action that after some iterations and edge case handling, is dealing with every sample file I've asked of it. It's a shell script that uses pdftotext to do just that, then awks for the first text appearing after the PAY EXACTLY line. This extracts the payee to a variable, which is then used to create a matching folder if nonexistent.
swy
 
Posts: 2
Joined: Thu May 22, 2025 1:40 pm

If that works for then more power to you. You can have Hazel also match against the contents in the way you described but it's up to you.
Mr_Noodle
Site Admin
 
Posts: 11888
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support