Using Automator

Hazel rules can use Automator to process matched files if you choose the “Run Automator workflow” action. (Unlike AppleScript, JavaScript, and shell scripts, Automator cannot be used in a rule condition , only in an action.) The file or folder that was matched is passed to the Automator workflow as input.

Using Automator to create actions enables you to extend Hazel’s built-in capabilities without having to write any code. Automator workflows can, for example, rotate or resize images, send files as attachments to email messages (see example below), make changes to your Contacts or Calendar data, or save text to an audio file—all things Hazel can’t do on its own.

To create an Automator workflow and use it in a Hazel rule:

- Open Automator (in Macintosh HD ▸ Applications ▸ Utilities).

- Click “New Document.” (Or, if Automator is already running, choose “File” > “New”.)

- Select either Workflow or Service as the document type and click “Choose.”

- Build your workflow (see below for an example). If your document type is Service, make sure the top of the workflow says “Service receives selected files or folders in Finder,” as shown below. (This option does not appear if your document type is Workflow, but that doesn’t prevent the workflow from accepting files and folders from the Finder.)

- Choose “File” > “Save” to save your workflow. (If you selected Service as your document type, the workflow is saved to Macintosh HD ▸ Users ▸ your-username ▸ Library ▸ Services. Otherwise, navigate to the location you want to save the workflow and click “Save.”)

- Now, in Hazel, open or create a rule, and choose “Run Automator workflow” as an action, choose “Other” from the second pop-up menu, navigate to the workflow you saved in the previous step. Click “Open.”

- Click “OK” to save the rule.

The following example workflow (shown here as Workflow document type, rather than Service) sends an email message (with whatever address, subject, message, and account you fill in), with the processed file as an attachment:

SEE ALSO

Using AppleScript or JavaScript

Using Shell Scripts