|
![]() |
Smart Item Scripts |
Smart item scripts are AppleScripts or JavaScripts run by an specialized actions in a smart rule or batch processing. These actions allow you to extend the possibilities beyond the already powerful pre-defined actions. There are three actions you will use: one simply runs code on matched items, the other can also handle incoming and outgoing data, and one that handles input. Script Actions Apply Script: This action runs AppleScript or JavaScript for Automation (JXA) code on the matched items. It runs as a standalone action, not receiving or passing along any data to its surrounding actions. It is often used for specific functions not available in the pre-defined actions. For example, using a specific tag on a document for filing or setting metadata. This action also has the advantage of being able to quickly process multiple documents. Set Script Input: This optional action functions as a variable, a temporary container for a value to be passed on to the Script with Input/Output: This powerful action contains a script handler that receives input and can also send information to actions that follow it. Getting information from other steps in your process opens up new opportunities for deeper automation. To accept input from a previous action, use the If you examine some of the built-in scripts, you can see examples of input and output. For an example output only, the External Scripts External scripts are accessible to any rule or configuration. So if you have code that would be useful in more than one process, saving them externally is a good idea. To run an external script, add the action, select In the We have compiled a list of the pre-installed scripts, for everyday use and your education. Embedded Scripts If you are writing a script for a specific smart rule or batch process, you can use an embedded script. The code is part of the action and can't be used by another other smart rule or configuration. To create an embedded script, add an For those new to scripting, there is a pre-built handler for each type of action. Terminology Apply Rule: These scripts are defined by this handler:
Script with Input/Output: These scripts are defined by this handler:
External Debugging While there isn't a step-by-step logging of all actions in a smart rule, when you are using a script action, errors will be reported in the Log window or toolbar button. However, if you're writing the script in Apple's Script Editor, here are two core snippets you could use to develop and test the script:
After you have the script working, you can copy and paste it into the script in your smart item. |