2 min read

How To Send Custom Push Notifications When Hazel Adds Files to Apple Books

I use the macOS app Hazel to automate a bunch of tasks on a Mac mini. Hazel makes it incredibly easy to manage files by applying rules to folders and performing actions like moving, renaming, or executing scripts. Most of my Hazel rules revolve around moving files synced via Syncthing to my desired archive locations. Using Hazel I automatically add PDFs I download to my iCloud folder to Apple Books.

Today, I took it a step further by enabling push notifications with Pushover whenever Hazel adds a file to Apple Books. This small tweak ensures I know exactly when a PDF is available to read. The setup was straightforward, and I’ve shared the steps below so others can replicate it.

I originally started exploring Pushover for sending notifications from the Apple Home app, but I found way for that app to send push notifications even when a security alarm is adjusted via a geofence. However, I’m glad I found another use for Pushover!


How to Set Up Hazel and Pushover Notifications for Apple Books

Step 1: Create a Pushover Account and API Token

  1. Go to Pushover.net and create an account.
  2. Create a new application to get your unique API token.
    • You’ll need both the API token and your User key for the script.

Step 2: Set Up Hazel Rule

  1. Open Hazel and create or edit the rule that processes the PDFs.
  2. Add conditions to ensure Hazel only runs this rule for PDFs in your watched folder. For example:
    • If extension is pdf
  3. Add an action to run a shell script at the end of the rule.

Step 3: Write the Shell Script

Here’s the script I use:

#!/bin/bash

# Pushover API credentials
API_TOKEN="your_pushover_api_token"
USER_KEY="your_pushover_user_key"

# Extract only the file name from Hazel
FILE_NAME=$(basename "$1")

# Send push notification
curl -s \
  --form-string "token=$API_TOKEN" \
  --form-string "user=$USER_KEY" \
  --form-string "message=Hazel added file: $FILE_NAME to Apple Books" \
  https://api.pushover.net/1/messages.json
  • Replace your_pushover_api_token and your_pushover_user_key with your Pushover credentials.
  • The script uses basename to extract just the filename (e.g., File.pdf) from the full file path Hazel passes to the script.

Step 4: Add the Script to Hazel

  1. In the Hazel rule editor, choose the "Run Shell Script" action.
  2. Copy and paste the script into the editor.
  3. Hazel automatically passes the file path of the processed file as $1 to the script—no additional configuration needed.

Step 5: Test the Rule

  1. Drop a PDF into the folder monitored by Hazel.
  2. Hazel will process the file, add it to Apple Books, and trigger the script.

You should receive a Pushover notification like this:

Hazel added file: File.pdf to Apple Books

Additional Notes

  • Why Pushover? I discovered Pushover recently, and its simple API makes it perfect for custom notifications like this. Plus, it works across all my devices.
  • If you want to batch notifications for multiple files or customize the message further, you can extend the script to handle more complex scenarios.

This small upgrade to an existing automation is a nice way to learn when new reading material is ready to consume in Apple Books.