Home

Appendix

Application Icon   Smart Rule Scripts

Smart Rule scripts are AppleScripts run by an Execute Script action in a smart rule. These scripts allow you to extend the possibilities beyond the already powerful pre-defined actions.

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 Execute Script action and choose External. The next dropdown lists any available AppleScripts 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:

  • Icon
    Check Links: Check if bookmarks are valid.
  • Icon
    Close All Databases: Closes all databases but the Global Inbox.
  • Icon
    Download Bibliographic Metadata: Attempts to retrieve the digital object identifier (DOI) of the document and set the title and metadata.
  • Icon
    Move Into Database: Moves indexed files into the database.
  • Icon
    Move to External Folder: Moves imported files out to the Finder when they're located in an indexed group.
  • Icon
    Reminders - Next Week: Set a reminder for a week from the current time and date.
  • Icon
    Reminders - Remove: Remove an applied reminder from the matched item(s).
  • Icon
    Reminders - Tomorrow: Set a reminder for the same time tomorrow.
  • Icon
    Tags - Add Keywords: Automatically adds Tags from the concordance of the matched file.
  • Icon
    Tags - Assign: Automatically adds tags, based on Apple's machine learning technology for images or hashtags and known tags in titles and content.
PRO
  • Icon
    Downloads - Add Embedded Images: Add embedded images to the Download Manager. Used with HTML-based files, e.g., web archives, etc.
  • Icon
    Downloads - Add Linked Images: Add linked images to the Download Manager. Used with HTML-based files, e.g., web archives, etc.
  • Icon
    Downloads - Add Podcasts: Add detected podcast links images to the Download Manager. Used with podcast RSS feeds containing download 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 an AppleScript directly in the smart rule's editor.

To write an embedded script for a smart rule, add or specify an Execute Script action and choose Embedded. 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 learning AppleScript, 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. Take note of it.

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