Creating a Script to automate sequentially entered Menu commands

Good morning!

Is it possible to automate the input of sequential menu commands, such as the following

File: Verify and Repair Database
File: Check File Integrity
File: Optimize Database

I created a Keyboard Maestro script is designed to automate the process of (1) Verifying and Repairing Database (Shift-Cmd-Y), Checking File Integrity (Ctrl-Sift-Cmd-Y), Optimizing Databases (Shift-Cmd-K). To start process, select the top DevonTHINK database, and press “Run.” Repeat sequentially through all open databases. Below is a screenshot of this process.

Two Questions:

(1) Is there a way of performing this kind of script inside of DevonTHINK using native commands?

(2) It is possible to have each step wait until the previous step has finished?

As my Keyboard Maestro script currently stands, I have inserted 1.5 second delay between each step, while allowing a full five seconds pause before running the last step which invokes an “Optimize Database command.” Several of my DevonTHINK databases are so large that it takes longer than 5 seconds to check the file integrity, so the last step is skipped and I must manually enter (Shift-Cmd-K) to optimize the database.



Verify and optimize are verbs in DT’s scripting dictionary, as is “check integrity”. So why go through all these steps instead of calling them directly from a script? Especially as GUI scripting is messy and not robust.

See e.g. menu Scripts > Data for two examples.

1 Like

Dear @chrillek and @cgrunenberg,

Thanks so much for your replies. I looked through the Scripts menu but MISSED the Scripts > Data sub-dir that containd exactly what I was looking for. I looked through Joe Kissel’s book on DT3 but didn’t find much that would help me with scripting. Do you have any suggestions on where I can turn to learn more about automating from within DT3?



Others will probably tell you about AppleScript, which I don’t use. If you want to know about JavaScript scripting, you can search the forum for examples. There’s also Scripting with JXA | JavaScript for Automation (JXA) on JavaScript for automation with some examples for DT and other apps.
And then there’s the manual with its section on “Automation”.

Thanks! I have Sal Soghoian’s book on AppleScript 1-2-3, and have muddled-my way through several chapters, and have adapted several scripts to be useful in my workflow. But, still. . . I am very much a beginner. ChatGPT has been helpful in suggesting some bash scripts that have also been useful in automating terminal commands. I worked my way through MacSparky’s fieldguide on DT. After 45 years in the Win/Tel world, I jumped ship three years ago, diving head first into macOS, and have not looked back. Goodbye Word—Hello Markdown. If I had been aware of DevonTHINK sooner, I would not have waited so long! It is an amazing way of storing and accessing all my files.

1 Like

If you’re happy with AS, use it. I find it terribly verbose and tedious to write.

But be aware that it’s lacking many features available in other, modern languages (notably JavaScript). For example string methods, regular expressions, functions as first-class citizens, support for data types like dictionary and set (yes, I know about AppleScript records. And I know also that you can’t iterate over their keys). AS has not been worked on since ages. But even Apple has to update JavaScript to keep Safari working…

1 Like

I am curious about the use case? What is it about your databases – or. your concerns about DEVONthink – that would require automating the triggering of these infrequently-used commands on a regular basis?

(Consider also, that the hours spent trying to figure out how to automate a sequence of commands adds up to more time than actually clicking the menu commands themselves over the course of a year or more. Not everything needs automation. Of course, “because I can” is an inarguable rationale LOL.)


My concerns over file integrity go back several months to when I have having problems syncing my databases with an iPad and iPhone DTTG via CloudKit. They would get out of sync, and files would go missing, etc. If I added web-clippings via DTTG, they sometimes would not show up in DT, and vice versa. I had to completely delete DTTG from both devices, and start over several times, until I realized (from reading this forum) that the problem was likely caused by CloudKit. When I switched to syncing via Bonjour over a local network, all those problems went away. As a precaution, I have continued to verify the file integrity of my twelve DT databases, but (honestly) have experienced ZERO syncing issues in recent months. I wanted an automated way of performing this verification, instead of manually performing the three step process on each on the twelve separate databases. Knowing that I can use Scripts > Data command to perform this task is much easier than the manual or Keyboard Maestro approach. Thanks for all the help, guys! Yours, Mark


I appreciate the answer, thank you.

I’ll mention, as a testimony, that in the last 17 years I have never needed to check or verify the integrity of the 6+ DEVONthink databases that have been open for 90% of that time. The reliability of this product is far greater than any other.

(Certainly better than iCloud, which was probably designed in a pre-school class project :exploding_head: )


This is pretty remarkable. Do you use indexed folders at all? I agree wholeheartedly that DEVONthink is amazingly robust, but even I have had my share of failed integrity checks and having to rebuild databases. This disturbs me when it happens, and recalling past occasions, I think it usually involves files stored or edited outside of DEVONthink. Reading that someone has never needed to do it is making me wonder what I’m doing wrong …

I’ve always used both indexed and internal documents with DEVONthink databases.


I just can’t get over this :-). I’m sorry to pester you with more questions, but do you also synchronize the databases with other devices or computers? If so, which sync method(s) have you used all this time?

Bonjour sync. I used to do Dropbox when sync first came around (10 years ago?), but don’t want that thing on my computers anymore. I tried CloudKit for a few weeks. Went back to Bonjour.