Hazel, KB what works for this date based automation?

What I want to do is be able to scan my bus ticket and snatch the expiration date and make a calendar entry to remind me to refill it. So getting the ticket to be scanned and OCR and wind up in iCloud drive is the easy part using Scanbot.

The second part I don’t know how to do gracefully, Hazel can quite easily pick up the document and identify the expiration date but with that data, the only thing I can do is rename the file. So how would you guys solve this? Get KB to pick up the file and execute some script magic or is there a better way?

Hazel can run shell scripts or AppleScripts, so after you have the date parsed, you should be able to create an event on your calendar using AppleScript.

Here’s one example that I found fairly easily:

From developer.apple.com: Calendar Scripting Guide: Creating an Event

macos - Applescript to create set iCal events - Stack Overflow
(note that this is old so it refers to iCal instead of Calendar as the app name.)

Hi and thanks, I looked into this but came to the conclusion that Hazel currently can’t pass variables to Shell or AppleScript.

It can, actually!

There’s some information on passing custom tokens to AppleScript on this page:

https://www.noodlesoft.com/manual/hazel/attributes-actions/using-applescript-or-javascript/

The part you will need will be under the heading ‘Input Attributes’. :slight_smile:

1 Like

Wow! just wow, it worked like a charm. Well not a charm since Hazel is a mess in Catalina but still it works! can not thank you enough.

So if anyone else would like to use it here is how i did it.

  • Fetch the date via pattern matching in Hazel Save it to a variable called “date 1”.
  • Add the variable as an attribute in Hazel.
  • Finally add the script.
tell application "Reminders"

set theDate to item 1 of inputAttributes

# Select the relevant list in Reminders.app

set myList to list "Your Calendar"

tell myList

# Create the reminder

set newReminder to make new reminder

set name of newReminder to "Your reminder text"

set remind me date of newReminder to theDate

end tell

end tell
2 Likes