I’m attempting to write a script to automate and publish pdf Layouts. However, the following two actions seem to be ignored by Dorico’s macro recorder. Either one would solve my problem:
- In Print mode > Graphics, after clicking Export, to click the Overwrite button if the Create New / Overwrite dialog appears.
- Also in Print mode > Graphics, to enter a path into the Destination Folder field.
This is my first attempt at scripting Dorico. Am I correct that these actions indeed not supported by Dorico’s macros?
Background:
My script wants Dorico to ALWAYS Overwrite and NEVER Create New, hence action 1. Alternatively, I could set the destination to an empty “scratch” folder. Then, the pesky Create New / Overwrite dialog would never appear, and a shell script could move the pdfs to my actual destination, overwriting. I would change the Destination in my project templates to the “scratch” folder. Clever! But I have 141 Dorico projects already created which I often update, so I’d like another script to run one time and change this path in 141 projects, hence action 2.
Is there any workaround other than GUI scripting? Dorico project files seem to be mostly an unintelligible binary blob.
Thank you, @asherber. Well, since I must use GUI scripting, I’ve of course tried to implement my idea #2, writing a script to change the Destination Folder of my 141 Dorico projects. This idea only needs to work for 1 day, so the fragility of GUI scripting will not matter.
I also realized that, since Destination Folder is per Layout, I also need my GUI script to select all layouts in the left sidebar of the Print mode tab before entering my “scratch” folder as the new Destination Folder.
I’m running Dorico on macOS 26. Since GUI scripting is difficult, I worked with Claude Code (artificial intelligence, AI) for about 2 hours. We can read the Layouts List OK, but even after trying a half dozen different approaches, we cannot get a script to successfully select or click any of them. Apparently, this is because Dorico is built on the Qt framework. It appears that, although Qt exposes accessibility information, it seems to not respond to any System Events click or select or accessibility (AXPress) commands. Dorico’s controls have no actions.
So Claude tells me that my only option is to go install a tool called cliclick via Homebrew, which supposedly simulates human clicks using screen or window coordinates. Claude thinks that Dorico will respond to cliclick.
But I need to quit for today. Any better ideas out there? Has anyone ever tried to automate the macro-unable controls of Dorico with anything like cliclick?
I’m on windows, but I’m pretty sure that Mac users can successfully use Keyboard Maestro to click things.
I also suspect that ai will not be very helpful with Dorico scripting, since there data to train on.
1 Like
I did get this script working good enough to convert my 144 Dorico projects. I don’t know if Keyboard Maestro would have worked, but I preferred cliclick because I presume, being a command-line tool, it is more lightweight than Keyboard Maestro. And, no, because AppleScript and GUI scripting in particular are so much trial and error (75% of the commands which should work do not work) there is no way I would have ever completed this endeavor without using Claude Code to dig through the internet, find more commands for me and suggest other code possibilities that might work with Qt apps like Dorico. It was Claude that suggested cliclick, which I had never heard of but turned out to be essential.
I don’t know if there is such a thing as GUI scripting in Windows, but in macOS, even with copious waits for the system to respond (delay commands in AppleScript), I’ve found that GUI scripting commands only work about 99% of the time, with no pattern or explanation of the failures. Since my script executes about 5 GUI scripting commands while processing each project, that means only about 95% of projects will be successfully converted. My script therefore detects failures after performing each command. If a failure is detected, it adds that project to a list of failed projects and moves on to the next project. After all are done, the script user may re-run the script on the listed failed projects. For my 144 projects, all succeeded on the second run.
In case anyone has a similar need, here is the script:
Dorico Change Export Destinations.scpt.zip (46.6 KB)