

The scripts execute in a different environment than in Terminal, which means that certain environment variables (such as a custom PATH and aliases) may not be set. When working with shell scripts in Hazel, keep the following in mind: Shell scripts take just one argument, $1, which is the full path of the file or folder being processed. Unlike AppleScript and JavaScript, shell scripts in Hazel can neither accept import attributes nor export custom attributes. If you’re already comfortable writing shell scripts, using them in Hazel should be quite natural. A shell script in an action, likewise, can process the matched file or folder using any of innumerable command-line utilities. For example, a shell script in a condition could employ the grep command to perform sophisticated pattern-matching on the file using regular expressions. Like AppleScript, JavaScript, and Automator, shell scripts enable Hazel to do things it’s unable to do on its own. Scripts can be written in any language (including Perl or Python), as long as you tell Hazel which shell or interpreter to use. In an action, the shell script can do pretty much anything (which may involve the file or folder being processed, but doesn’t have to). In a condition, the shell script tells Hazel whether or not the file or folder being processed matches. Hazel can use shell scripts, or even standalone command-line programs, in either conditions or actions.
