Custom List Attributes

This token can create a list based on a rule condition and then reuse that list in an action. (If you want to match a specific item in a list, you should instead use  Custom List Item Attributes .)

For example, suppose you want to create a list of tags from an enclosing folder, and then apply those matching tags to each item within the folder. You can create a custom list in your condition that captures the tags, then refer to that list in the “Add tags” action.

To create a custom list attribute:

  • Create a condition with an attribute (such as “Tag” or one of numerous “Other” options) that may be used more than once per item, and that uses a match-related verb in the second pop-up menu (“matches”/“does not match,” “match”/“do not match,” or “contain match”/“do not contain match”).

  • Note:  Custom lists can also work with lists in text (such as  apple,orange,banana ) if your condition uses an attribute such as Name, Comment, or Contents. This process, which is slightly different, is described later on this page.

  • Drag the “Custom List ( )” token to the pattern field.

  • Type a name for your custom list attribute.

  • Type, and/or drag one or more tokens, into the field below the “Name” field to create the pattern to match against. Hazel will apply the pattern to each item in the list of attributes it examines, and create a new list comprising all those that match. (To get a copy of the entire list, drag the “Anything (…)” token to the pattern field.)

  • Click Done, then click Done again.

To use a custom list attribute in an action:

  • Choose an appropriate action. The “Add tags” action is the only one in Hazel 6 that can apply multiple list items individually. However, you can convert the list to regular text by choosing an action such as “Rename,” “Sort into subfolder,” “Add comment,” or “Display notification”; then, click the token for the custom list, choose Edit List Separator from the pop-up menu, and type the character(s) you want to use to separate list items. (For example, you could rename a file using the names of the tags in its parent folder, separated by bullet characters:  Tag1•Tag2•Tag3 , or put those tag names in a comment.)

  • Drag the custom list you created in the condition into the pattern field, along with any other desired text or pattern. (In the case of the “Add tags” action, first choose “Dynamic Tag…” then drag in the custom list. See  Using Patterns in Actions  for more information on Dynamic Tags.)

To illustrate how this works, let’s use the example mentioned above: using matching tags from an enclosing folder to apply tags to items within it.

First, we specify “If  all  of the following conditions are met for  its enclosing folder ” and add the condition “Tags contain match.” We drag the “Custom List ( )” token to the pattern field, name it “parent tags,” and drag the “Anything (…)” element into the pattern, as shown below. This means that, no matter how many tags the enclosing folder has, Hazel will create a list, called “parent tags,” containing all and only those tags.

Next, we add the “Add tags” action to make use of our new list of tags containing only numbers. We first click in the “Add tags” field and choose “Dynamic Tag…” from the pop-up menu. We name the dynamic tag “new parent tags.” Then, we drag the “  parent tags” token we created in the condition to the pattern field.

Now, suppose Hazel is monitoring a folder that has one or more tags applied to it. The condition matches all those tags and makes a list, “parent tags,” with all those tags on it. The action applies that list of tags to items newly added to the monitored folder.

You can also filter the list such that the new list is a subset of the original one. For example, if you wanted to apply to the enclosed items only those tags from the parent folder consisting of digits, when creating the list attribute in the condition, instead of using the “Anything (…)” token, you could drag in the “Number (123)” token, as shown below, to make it more specific.

As mentioned above, custom lists can also work with lists in text (such as  apple,orange,banana ), such as may be found in a file’s contents, comment, or name—regardless of what character separates the list items. When matching text, a condition must always capture the entire list; it can’t filter the list as in the example just above. However, if the source attribute contains multiple matching lists, you can specify which one of those lists to capture.

To create a custom list attribute from text:

  • Create a condition with an attribute (such as “Name,” “Comment,” or “Contents”) that consists of arbitrary text, and that uses a match-related verb in the second pop-up menu (“matches”/“does not match,” “match”/“do not match,” or “contain match”/“do not contain match”).

  • Drag the “Custom List ( )” token to the pattern field.

  • Type a name for your custom list attribute.

  • Type, and/or drag one or more tokens, into the field below the “Name” field to create the pattern to match against. Hazel will search the attributes it examines for a list whose individual elements match your pattern, and assign the name you entered to that list. (To create a custom list in which each element can be any combination of characters, drag the “Anything (…)” token to the pattern field.)

  • Using the List Separator field at the botto m of the popover that appears, enter one or more characters (such as a comma) or choose Newline or Tab from the pop-up menu to tell Hazel how to identify individual items in the list. For example, if a text file contains a list like  dog, cat, bird  that field should contain a comma followed by a space, since that’s what separates the list items.

  • Click Done.

  • Optionally, to choose a particular list from a source that contains more than one, change the field at the bottom: “Match the __ occurrence (from the beginning/from the end).”

  • Click Done again.

Your custom list now contains every item in the original text list, and you can use that custom list in an action.

To use a custom list attribute from text in an action:

  • Choose an appropriate action. The “Add tags” action is the only one in Hazel 6 that can apply multiple list items individually. However, you can use the list as regular text by choosing an action such as “Rename,” “Add comment,” or “Display notification”; then, click the token for the custom list, choose Edit List Separator from the pop-up menu, and type the character(s) you want to use to separate list items.

  • Drag the custom list you created in the condition into the pattern field, along with any other desired text or pattern. (In the case of the “Add tags” action, first choose “Dynamic Tag…” then drag in the custom list. See  Using Patterns in Actions  for more information on Dynamic Tags.)

Let’s put this “custom list attribute from text” idea all together by creating a rule that looks in the contents of text files for lists containing sequences of digits, separated by commas, such as:

10,20,30,40,50

123,456,789

1.3,7800,3.41459

Suppose, for the sake of this example, that you want to drag many such text files into your monitored folder, but it’s always the  second  list of numbers you’re interested in. You want the rule to add all those numbers to a comment, separated by a bullet surrounded by spaces. Here’s what the condition might look like:

The condition is “Contents contain match” with a new custom list item as the pattern. That list, which we name “Number List,” in turn contains just the token  , and the List Separator field at the bottom shows a comma. After we click Done, we make another change in the parent pattern popover: using the arrow buttons at the bottom, we set it to “Match the 2nd occurrence from the beginning.”

The action is “Add comment,” and its pattern consists of the Number List token we created in the condition. We click the little arrow on the right side of the token and, in the List Separator field, type a space, a bullet, and another space.

Now, if we add to this monitored folder a text file with contents like those given earlier, Hazel changes the Finder comments for that file to look like this:

SEE ALSO

Using Match Patterns in Conditions

Custom Text Attributes

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