Home | Appendix

|  |  | Script Editor and Assistant

For those interested in scripting, a specialized scripting interface is now included in DEVONthink. With it you can draft a variety of scripts in both AppleScript and JavaScript (JXA). Covering the types of scripts used in-application, you can start creating scripts and open them in an external editor, as needed. The Script Editor window can be opened via Data > New > Script as well as the context menu of the item list and the Action menu. The window is composed quite simply. You have a mandatory Name field. Following that is an optional Info field where you can include a description or instructions, appearing as comments in the script. Next is the Type dropdown where you choose one of the types of scripts found in DEVONthink. The supported types are: Generic: This is a generic script containing the boilerplate code for handling a selection of items. It can be used for many purposes. Reminder: This creates a draft reminder alarm script in the Annotations & Reminders inspector. The appropriate handler is already included. Smart Rule: Used with the `Apply Script` smart action in smart rules and batch processing, this contains the appropriate handler and code to be used in smart actions. Output: Used in the `Script with Input/Output` smart action, the template code contains the handler ready to modify and use. Finally, at the bottom of the window, is the editing pane where you can work on the code. As you work, you can press the Compile button, shown with a small hammer. This lets you check if your code has any syntax issues. And finally, the OK button will generate a script file with the code for you to open in an external editor, etc. Script files are saved as text-based `.applescript` files that can be edited in DEVONthink or opened externally, e.g., in Script Editor. You can read more about the various types of scripts in the Automation chapter. PRO Script Assistant If you have set up access to external AI in the Pro and Server editions of DEVONthink, you may be able to use it to write or modify the code. Below are the places you can find the Script Assistant. Bear in mind, the code is a draft and the script may not work correctly in its initial form. However, the AI is aware of several common scripting errors and will attempt to correct them in its output. You can ask it to refine the code. Script Editor: Below the Type dropdown in the Script Editor window is a field where you can enter a prompt to be used for a script. Click the icon to the left of the field and choose an available AI model that supports coding. After you write your prompt, press the ↩ Return key and AI will try and draft a script fulfilling the requirements you've set. Smart Actions: Another place you can access external AI is when editing a smart item script in a smart action, i.e., `Apply Script` and `Script With Input/Output`. In a smart rule or batch processing configuration, edit the internal AppleScript or JavaScript. You will see the AI model button to the left of the Script Assistant field where you enter your AI prompt to compose or improve the script. Reminders: When setting an reminder alarm on an item, you can add a reminder alarm script. For the alarm, choose `Execute AppleScript` or `Execute JavaScript`. Click the button to the right to open the script editor. Here you can directly compose a reminder script or again, use external AI to describe the script. Enter the prompt, press ↩ Return key, and let AI generate draft code for you.