Custom Text Attributes

You can use add “Custom Text ●” token to a pattern to create your own custom text attribute, which then becomes a token available for any patterns in any subsequent conditions or actions in this rule. In addition, it’s available as an attribute (that is, an entry in the leftmost pop-up menu) in any conditions (in this rule only) after the one in which you define it.

Note: You can also create custom text attributes by exporting attributes from an  AppleScript or JavaScript .

Custom text tokens are useful in cases where you want to save some matched text and insert it somewhere else. For example, let’s say you have a bunch of files whose name start with a 5-digit ZIP code. You can define a token that matches that portion of the name and call your custom token “ZIP code.” This new token can then be dropped into a “Sort into Subfolders” pattern to sort the files into folders based on ZIP code.

To create a custom text token, click the “Custom Text ●” token or drag it into the field at the top of the popover. When you do so, a secondary popover appears, in which you can edit your custom token:

As in the main match pattern editor, you can specify a pattern here. You must also enter a name to identify your custom token; that name then appears in the first pop-up menu for later conditions in this rule, as well as in the list of tokens you can use to create patterns for the rule’s conditions or actions. Here, the token is named “ZIP code” and it matches five consecutive digits. (To help you distinguish custom text attributes, Hazel prefixes their names with ● when they appear in tokens or menus.) Click “Done” when you’re finished creating your custom text token.

When you’re done editing, your custom text token appears, with the name you specified (prefixed with ●) in the other pattern popovers for the current rule (1), which you can then drag into your patterns (2). (It also appears as an attribute at the bottom of the leftmost pop-up menu for later conditions in this rule.) When Hazel runs the rule, it keeps track of what text matched it, and when your custom token is used in the pattern for an action (see  Using Patterns in Actions ), Hazel inserts the text that was matched.

Using the “ZIP code” example above, if a file has the name  10101-Survey , Hazel assigns the “● ZIP code” attribute the value  10101  (the “● ZIP code” token matches five digits in a row). When sorting into subfolders, the file is moved to a folder called  10101 .


Using Match Patterns in Conditions

Custom Date Attributes

Custom List Item Attributes

Custom Table Attributes

Reusing Custom Attributes in Condition Patterns

Using Patterns in Actions

Using Custom Attributes in Actions