Home | Appendix

Quick links: |  | Adding an External Script Adding an Embedded Script Debugging Terminology

|  |  | Smart Rule Scripts

Smart Rule scripts are AppleScripts or JavaScripts run by an Apply Script action in a smart rule. These scripts allow you to extend the possibilities beyond the already powerful pre-defined actions. They also work with batch processing. Note: Smart rule scripts will be executed based on the event handler in the specific rule. For testing, it can be useful to set the event to On Demand. This way you can select the rule to see its matches, then Control-click it and choose Apply Rule to run it and see the effects on the matched items. Also be aware the effects of smart rules are very broad, i.e., they affect all the items they match. While you are testing, it's a good idea to put some limiting criterion in place. For example, instead of matching all images in all databases, try matching images in a specific group or only images that begin with "Screen". Adding an External Script To add an external script to a smart rule, add an Apply Script action and choose External. The next dropdown lists any available scripts in the `~/Library/Application Scripts/com.devon-technologies.think3/Smart Rules` directory. Add any of your own scripts to this directory to make them available for any smart rule you define. Here is a list of the pre-installed scripts, for everyday use and your education: Check Links: Check if bookmarks are valid. Close All Databases: Closes all databases but the Global Inbox. Download Bibliographic Metadata: Attempts to retrieve the digital object identifier (DOI) of the document and set the title and metadata. Move Into Database: Moves indexed files into the database. Move to External Folder: Moves imported files out to the Finder when they're located in an indexed group. Reminders - Next Week: Set a reminder for a week from the current time and date. Reminders - Remove: Remove an applied reminder from the matched item(s). Reminders - Tomorrow: Set a reminder for the same time tomorrow. Tags - Add Keywords: Automatically adds Tags from the concordance of the matched file. Tags - Assign: Automatically adds tags, based on Apple's machine learning technology for images or hashtags and known tags in titles and content. PRO Downloads - Add Embedded Images: Add embedded images to the Download Manager. Used with HTML-based files, e.g., web archives, etc. Downloads - Add Linked Images: Add linked images to the Download Manager. Used with HTML-based files, e.g., web archives, etc. Downloads - Add Podcasts: Add detected podcast links to the Download Manager. Used with podcast RSS feeds containing downloadable links. Adding an Embedded Script There are times you may need to add some code for a specific situation. Similar to some other macOS utility applications, DEVONthink allows you to write a script directly in the smart rule's editor. To write an embedded script for a smart rule, add or specify an Apply Script action and choose AppleScript or JavaScript. Click the Edit Script button and a popup will appear with a pre-built handler in place. Add your code as necessary, then press the compile button, the one with the stylized eye, to make sure it compiles correctly. If it does, you will see the code format itself subtly. If not, you will hear a system alert. When done, click outside the popup to dismiss it
Note: For those new to scripting, the repeat loop in the pre-built handler is a very common (and useful) code snippet for processing all files returned by a smart rule. In most cases, work inside that loop.
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. Terminology Smart Rule scripts are defined by a specific handler: `on performSmartRule(var)`, where `var` is the variable representing items matched by the smart rule.
Example: on performSmartRule(theRecords) tell application id "DNtp" repeat with theRecord in theRecords if (name of theRecord as string) contains "Piglet" then set state of theRecord to true end if end repeat end tell end performSmartRule