Mac OS X's Folder Actions feature lets you assign AppleScripts or Automator workflows to specific folders in order to automate file-management chores such as renaming files or resizing images. Folder Actions are a great idea, but they have two problems: They require AppleScript or Automator, which many Mac users don't want (or know how) to use; and they're a bit of a blunt tool, applying to every item in a folder unless you specifically include filters in your script or workflow.
Hazel solves both problems. It duplicates the functionality of Folder Actions without requiring AppleScript or Automator, and it includes simple yet powerful filtering for restricting actions to specific files.
Open Hazel's pane in System Preferences, and you'll see a box on the left where you can select and add folders (only standard folders-you can't use Smart Folders, which essentially duplicate Hazel's file-filtering features). To the right is a Rules box that tells Hazel what to do with files inside the selected folder.
To add a rule, you click the plus sign (+), which presents you with a window that will be familiar to anyone who's built rules in Mail: First you give the rule a name, then you define which items the rule will apply to, then you define the actions the rule will perform. (Hazel supports Growl , so you can keep track of when rules execute.)
Files and subfolders can be selected by almost any feature you can imagine. The default pop-up list includes obvious criteria such as name, extension, and kind, but choosing the Other option lets you use any kind of Spotlight metadata, including such iTunes tags as Album and Year Recorded. You can use these types of metadata with all the usual operands: is, is not, contains, and so on. It would be nice if some of the more-obvious criteria, such as file extension, provided a pop-up menu for choosing common criteria, but you have to manually type everything-.txt and jpg, for example.
Hazel can also find folder items using some metadata of its own-the program tracks the specific time and date each item is added to a folder and the last time items in a folder were matched by a Hazel rule. So, for example, you can make a Hazel rule execute when it's been a week since a file was added to the folder. These criteria reflect one of the big differences between Hazel and OS X's Folder Actions: Hazel can monitor files perpetually, whereas Folder Actions execute only when something happens to or in a folder.
Hazel also provides a Preview Rule Matches feature, so you can test your filters before you actually use them. One small glitch I encountered using this feature: By default, Hazel doesn't check subfolders of the folder you're monitoring. To have it do so, you must specify that action as part of your rules.
Hazel's available actions
The list of actions Hazel can apply to selected files includes many file-management basics: copy, move, rename, and so on. (The rename option is particularly powerful, as it lets you use all kinds of pattern-matching variables.) Hazel can even import media into iTunes and iPhoto. If the built-in choices don't cover what you want to do, you can still choose to run AppleScripts and Automator workflows.
Rules execute in the order you set. However, unlike with Mail rules, Hazel applies to each file only the first matching rule-a file acted upon by, say, the first rule won't be affected by subsequent rules. The Ignore File action, designed to be listed first, takes advantage of this sequential approach to let you prevent Hazel from affecting particular files. Still, I'd like to see an option to apply multiple rules to a single item.
Hazel is smart enough to wait for Mail and Web-browser downloads to finish before applying its rules, but it's not so smart about downloads from, say, Bit Torrent clients-rules can execute before those downloads finish, causing problems with some actions. A workaround is to include a Date Added filter, so rules apply only to files that have been in a folder for a while.
Hazel can even work with Dropbox folders, opening up some interesting possibilities: If you're importing images to your MacBook while on the road, you could configure Hazel to, say, process those images using an Automator workflow and then move them to your Dropbox folder for syncing to your Mac at the office. And if Hazel is also running on your office Mac, that Dropbox folder could have Hazel rules attached to it.
Hazel also includes a feature for deleting files from the Trash based on how long they've been in the Trash, or when the Trash grows beyond a certain size. There's also an App Sweep feature, which, when you drag an application to the Trash, looks for and deletes the application's support files. (I didn't test this feature because I generally don't trust "app deleters" to reliably determine which files belong to a given program and which might be shared with others.)
Hazel's combination of power and ease of use makes it one of the handiest Mac utilities I've used, and the more I use it, the more I realize how powerful it could be. But there is the question of whether or not you need that power-unless you regularly download files or shuttle them from one device to another, you may not need Hazel's features. But if you do perform frequent-and repetitive-file-management tasks on your Mac, Hazel is a great tool for automating the job.
This story, "Hazel 2.3" was originally published by Macworld.