Batch Processing/Macro Script

I’ve managed to write a basic AppleScript that can export PDFs from multiple Dorico files using a sequence of shortcuts, which is relatively simple.

However, I’m trying to figure out a way to batch export the project stats for multiple files. Unfortunately, there’s no shortcut to export the stats (I can open the stats using a key command, but I cannot export them as a text file). To solve this, I tried recording a macro to export the stats. Once recorded, I could batch the process via AppleScript to open the file, run the Dorico script using the Jump Bar, and then close the file.

The issue I’ve encountered is that when I record the macro, it only captures the part when I open the Project Statistics window, but it does not recognize when I click the “Export” button. Does anyone have any idea why this might be happening or how to work around it?

Thanks in advance~

Normally adding the following after the window “Project Statistics” has been opened should work. In this case it doesn’t. I don’t know why.

tell application "System Events"
	click button "Export..." of window "Project Statistics" of application process "Dorico 5"
end tell

I think I’ve found a way to do it.

In the script snippet which I posted previously, replace the second line with the following:

	tell window "Project Statistics" of application process "Dorico 5"
		keystroke tab
		keystroke tab
		keystroke space
	end tell

A dialog should open for you to save the text file. You might want to change the location before hitting Enter.

P.S. A belated welcome to the Dorico forum.

1 Like

Thank you!

For some reason it’s still failing to click on the Export button

The following AppleScript works for me.
It assumes that a Dorico project is open, opens the Project Statistics dialog, then presses the “Export…” button after a 1-second delay.
A dialog then opens for you to save the text file.
At that point you will need to either 1) script a response or 2) manually change the “save” location or leave it as is then click on Save.

If a project is not open or the Project Statistics dialog is already open, the results will be other than what is intended. There is no error-checking.
The 1-second delay was necessary and is possibly what was preventing it from working for you. Depending on the speed of your Mac, it might need to be adjusted. Over some years of writing AppleScripts I have found that inserting a delay is often necessary. Particularly with applications (such as Dorico) which do not have their own AppleScript Library, once one command has been sent AppleScript generally does not check (and/or maybe has no way of checking) to see if that command has actually been completed before it moves on to sending the next command. A small delay (sometimes a longer one) will give the first command time to complete before the next one is sent.


tell application "Dorico 5"
	
	activate
	
	tell application "System Events"
		
		click menu item "Project Statistics..." of menu "File" of menu bar 1 of application process "Dorico 5"
		
		delay 1
		
		tell window "Project Statistics" of application process "Dorico 5"
			keystroke tab
			keystroke tab
			keystroke space
		end tell
		
	end tell
	
end tell

For some reason it is still failing to click on the Export button.
I used the exact same script and tried it on a file that is already open. I’ve increased the delay time as well, but I’m not that’s not the issue.

The script opens the project stats and stops here.

It may be related to whether you have the option set on your Mac to allow Tab to advance to different controls. In recent versions of macOS, look for the option called Keyboard navigation in the Keyboard pane in System Settings.

1 Like

@dspreadbury Thank you, Daniel, for pointing out that setting for Tab behaviour. I had created and tested the script under Big Sur (which does not have that setting), and it worked. After reading your post, I tried it under Sonoma with the Tab setting disabled - no joy. After enabling that setting - joy! Hopefully that is all that @Wissam will need to attend to.