Home | Appendix

|  |  | Shortcuts and Automator

Apple's Shortcuts and Automator applications were created to help non-programmers take some control of their machines. They allow you to visually string together simple steps to create an automated process. Though much more limited due to their linear nature and lack of debugging tools, they may still be useful for some situations. Additionally, they let you create other types of items like workflows, services, or Quick Actions. DEVONthink doesn't offer specific Shortcut or Automator actions. However, as DEVONthink has a deep and robust scripting dictionary, the `Run AppleScript` action in those applications opens up some automation opportunities. The key to integration with DEVONthink is passing or receiving file paths via scripting.
Note: While Shortcuts is newer, the tips presented here generally apply to both applications. And while we may investigate DEVONthink-specific questions regarding Shortcuts or Automator, we do not offer support specifically for them.
Getting information into DEVONthink As an example, importing selected files in the Finder can be accomplished by passing file paths to DEVONthink. To do this, use a `Get Selected Files in Finder` action before this `Run AppleScript` action:
Example: on run {input} tell application id "DNtp" repeat with thisFile in input import (POSIX path of thisFile) to incoming group end repeat end tell end run
Sending information out of DEVONthink For passing items from DEVONthink, this `Run AppleScript` action provides a list of file paths to be processed. This action should be placed before the third-party application's actions.
Example: on run {} tell application id "DNtp" if (selected records) is not {} then set fileList to {} repeat with thisRecord in (selected records) if (path of theRecord is not "") then copy ((path of theRecord) as POSIX file) to end of fileList end if end repeat end if if fileList is not {} then return fileList end tell end run
Note: In Shortcuts, the records' path likely needs to be passed as a `POSIX file`. Automator prefers POSIX paths, so use `copy (path of thisRecord) to end of fileList` instead. Also, you need to ensure the selected items are not groups or smart groups as they don't exist in the filesystem.
WARNING: Be very cautious when using the paths from DEVONthink. Actions like moving, deleting, renaming etc. would compromise your database. Immediately following the AppleScript action, use a `Save` action with the `AppleScript Result` in Shortcuts or the `Copy Finder Items` action in Automator to keep from modifying the underlying files in your database.