Home

Appendix

Application Icon   Triggered Scripts

Triggered scripts are AppleScripts that you attach to an item in DEVONthink (a group or document). Instead of being bound to a set interval like a reminder alarm, these scripts are executed every time you select the item. Such a script could change some metadata, force an update of indexed items, or many other habitual actions you may need to perform. So with some creativity and a bit of scripting, you can add your own custom behaviors when interacting with items in your database.

Items with attached scripts show an AppleScript property icon behind their name. And a toolbar search for item:scripted will show you items with attached scripts.

Triggered scripts can be stored anywhere, but are typically located in a folder within the ~/Library/Application Scripts/com.devon-technologies.think/Menu directory. Adding or removing a triggered script from an item in DEVONthink is done via scripting, using the attached script property for a selected record. Here is a code snippet you can use to attach scripts to selected items:

Example:

property dtScripts : (POSIX path of (path to library folder from user domain) & "Application Scripts/com.devon-technologies.think/" as string)

tell application id "DNtp"
if (selected records) is {} then return
set chosenScript to choose file with prompt "Choose a triggered script to attach to the selected item:" default location dtScripts of type {"scpt", "scptd"} without multiple selections allowed
repeat with theRecord in (selected records)
set attached script of theRecord to chosenScript
end repeat
end tell

Terminology

Triggered scripts are defined by a specific handler: on triggered(var), where var is the variable representing the item the script is attached to.

Example:

on triggered(theRecord)
tell application id "DNtp"
display alert "" & (name of theRecord as string)
end tell
end triggered