Hey guys, I’m looking for a way to have hazel fetch some variables from a file and help me posting some information on an Airtable Database.
Here’s the thing:
I have a municipality app that makes a standard invoice via a PDF file. That’s my input.
I already have in place a hazel rule that allows me to fetch:
Client’s name
Expediture date
Due date
Description of the service
Amount due
All those info gets parsed to the file name and the renamed file gets properly filed into a To Be Paid folder. When the payment has been made I change its status by moving the Invoice to a Paid folder. When it’s Due but has not been paid, Hazel moves it to a Due folder and prompts me to follow up.
It’s great for me only, but not so much to my partners that rely on an Airtable Database which some of us usually takes a little while to manually update.
Now I wonder if I could have the same informatiomation pushed to Airtable via it’s API so it would reflect the automatic status processing made by Hazel. Any hints of how could I push the same info automatically?
You can run a script as part of a Hazel rule, so I think you would leverage that and draw on examples in their custom API documentation. (I think the curl part is a shell script? Forgive me if I’m wrong.)
(To trigger an update when the invoice is paid you would probably need to set up a Hazel rule additional to what you have now just to watch that folder.)
You can use custom tokens that you already have as inputs to Javascript and Applescript. I’m not sure about shell scripts but if it’s an issue you can always put a shell script inside an Applescript using do.
I assume when the invoice is created you would want to “create a record” (which should just be a matter of tweaking the sample, and using the custom tokens) and when it’s changed to Overdue or Paid you would need to “update a record’.
To update the record you need the ID, but perhaps you can save this (I have been known to stick things like this in the file comments) when the record is created in the first place and then use it. Otherwise you could use some other unique criteria to “list records” each time, find the ID that way & then do the ‘update’ action.
I hope that gives you some idea of what might be possible. I’m just starting to play around with the Airtable API myself but their documentation seems about as user-friendly as it can be.
That’s a great API, indeed. And the double-pane view is great for both learning and, at least for non-coders like me, adapt.
The problem I’m currently facing is how to turn a Hazel match token (say, Client Name) into a variable I could use onto the Shell Script function on Hazel actions.
It’s not obvious, haha, I just happened to be fiddling with it yesterday. I just had a look and I don’t think you can with a shell script. But all is not lost! This is how to get the variables into AppleScript - have a look at the “Input Attibutes” section.
Then you should be able to have a shell script inside your Applescript by just writing do shell script “ (your script here) ” You can see some examples with variables included here too:
Oooh…what does your Hazel rule look like that fetches the data out of the PDF file? I’m trying to figure out how to get Hazel to pull a bit of info out of a PDF file and rename the file with that pulled info. Thanks!
This is old topic, info to pass tokens from Hazel to applescript to do shell/ applescript is here
rename the file with token, let script do the magic , and rename it again the way u like