Using Custom Attributes in Actions

Actions can refer back to custom attributes from match patterns (see  Using Match Patterns in Conditions  and  Using Custom Attributes ). This enables you to do things like:

  • Rename files with only part of the original filename.

  • Display a notification that includes the first line of text in a file.

  • Sort files into any of several subfolders based on their extension.

  • Apply tags based on the contents of comments, or vice versa.

  • Open with a different app depending on the domain name in the source URL.

Let’s look at three examples to illustrate the process of reusing a custom attribute in an action.

Note:  You may also want to learn about reusing custom attributes in  other conditions —see  Reusing Custom Attributes in Condition Patterns .


Rename Files with Part of the Original Filename

Suppose a monitored folder contains files with names like  TPS Report 2018-Q3.pdf  and  TPS Report 2020-Q2.pdf , and you want a rule to rename them with just portions of the original filenames, but rearranged—like  Q3 2018.pdf  and  Q2 2020.pdf . Here’s how you might do that.

First, set up the condition:

  • Choose “Name” from the first pop-up menu and “matches” from the second.

  • Click in the pattern field and type the text  TPS Report  (followed by a space).

  • Drag the “Custom Date  ” token into the pattern, type in the name “Year,” deselect the checkbox “Automatically detect date format,” and drag the “Year (99)” token to the attribute field.

  • Click the arrow on the right side of the 99 token and choose “1999” from the pop-up menu to specify that we’re looking for four-digit dates. The custom Year token should then look like this:

  • Click “Done” to dismiss the “Year” popover, then type a hyphen.

  • Drag the “Custom Text •” token into the pattern, type in the name  Quarter , and in the attribute field type the letter  Q  and insert the “Digit (1)” token. It should look like this:

  • Click “Done” to dismiss the “Quarter” popover. then click “Done” again to dismiss the match pattern popover.

The finished condition will look like this:

Next we move on to the action:

  • In the action row, choose “Rename” from the first pop-up menu.

  • Click in the pattern field and delete the “name” attribute (but leave “extension” in place).

  • From the bottom of the attribute list, drag the “• Quarter” custom text token to the beginning of the pattern field, then type a space and drag the “  Year” token to the pattern field, just to the left of “extension,” like so:

• Click the arrow on the right side of the “  Year” token and choose “1999” from the pop-up menu to specify that we’re using four-digit dates in the replacement name.

• Click “Done,” and then click “Save.”

This rule will now rename files with names like  TPS Report 2018-Q3.pdf  to something like  Q3 2018.pdf .


Rename a File or Folder Matching a List of Tags

Next, we use a list item attribute to match files or folders tagged with any word on a list, and then add the tag to the filename. For example, if the file  nothing.txt  has the tag “Red,” and “Red” is on your list, that file will be renamed  nothing Red.txt .

First, create the condition:

  • Choose “Tags” from the first pop-up menu and “contain match” from the second.

  • Click in the pattern field, and click the “Custom List Item ( )” token to add it to the pattern.

  • Name the custom list item “Tag Names,” and following the instructions in  Custom List Item Attributes , fill in the list as shown below. (For this example, we’re deliberately including only a portion of the default Finder tag names.)

  • Click “Done” to dismiss the custom list attribute item popover, then click “Done” again to dismiss the match pattern.

Now create the action:

  • From the first pop-up menu, choose “Rename.”

  • Click in the pattern field and type a space after the “name” token.

  • Drag the “  Tag Names” custom list item attribute up to the pattern field, inserting it after the space and before the “extension” token.

  • Click “Done,” and then click “Save.”

This rule will now add the text of any tag on your list to the filename of items in the monitored folder.


Sort Files into Subfolders Based on Extension

The final example rule sorts files into one of three subfolders: “Images” if the extension is  .jpg .jpeg , or  .png ; “PDFs” if the extension is  .pdf , or “Text” if the extension is  .txt .

To set this up:

  • Begin by creating folders with the above names (“Images,” “PDFs,” and “Text”) inside the folder you’re monitoring, so you can refer to them later.

Next, create the condition:

  • Choose “Extension” from the first pop-up menu and “matches” from the second.

  • Click in the pattern field, and click the “Custom Table ( )” token to add it to the pattern.

  • Name the custom table “Extension Map,” and following the instructions in  Custom Table Attributes , fill in the table as shown below. (You’ll note that we have three different rows that say “Images” for the Folder Name, since there are three extensions we want to match against for that folder.)

  • Click “Done” to dismiss the custom table popover, then click “Done” again to dismiss the match pattern.

Now create the action:

  • From the first pop-up menu, choose “Sort into subfolder.”

  • Click in the pattern field and drag the “  Extension Map” custom table up to the pattern field.

  • Click the arrow on the right side of the “  Extension Map” token and choose “Table Column” > “Folder Name” from the pop-up menu to indicate that you want the names from the “Folder Name” column to be used for sorting. Your action should now look like this:

  • Click “Done,” and then click “Save.”

This rule will now sort items into subfolders based on the extensions and folder names you specified in the table.

SEE ALSO

Using Patterns in Actions

Using the Counter Attribute

Using Match Patterns in Conditions

Using Custom Attributes

Custom Text Attributes

Custom Date Attributes

Custom List Item Attributes

Custom Table Attributes

Reusing Custom Attributes in Condition Patterns

Using Patterns in Actions