Hazel rules and variables for Airtable API posting

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?

I’m sure this could work!

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. :slight_smile: I’m just starting to play around with the Airtable API myself but their documentation seems about as user-friendly as it can be.

1 Like

https://airtable.com/api shows you exactly what curl requests want/need for adding, querying, etc. your Airtable base.

1 Like

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:


1 Like

Thanks! Definitely going to try this later!

There is one as well for shell scripts https://www.noodlesoft.com/manual/hazel/attributes-actions/using-shell-scripts/ . It doesn’t look like there is a way to pass anything other than the full file name.

Could you extract the information in a shell script 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!

In my case, since the pdf documents are very much uniform, I use the contents trigger and “contain match” with some variables, as shown here:


From there, it’s a simple rename (with those variables) and move sequence.

1 Like

Muito obrigado! (I have now exhausted my knowledge of Portuguese.)

1 Like

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