Trying to record script to save MusicXML

I want to create a script for saving MusicXML. It will need to bring up the save dialog box, make sure the right options are checked/unchecked, hit save, then hit “overwrite” when that dialog comes up. I tried to record this, but when I played it back, all it did was bring up the save MusicXML dialog, but didn’t make any further clicks.

Perhaps macros are not intended to interact with dialog boxes? Maybe they are just for modifying documents?

Would it be possible to write this script in Lua? Is there an API that provides access to saving MusicXML?

Why do I want a script? This is a very common action for me, and I have some pain in overusing the mouse.

I also tried creating a script in Keyboard Maestro, which is macro software for the Mac. However, it actually crashes Dorico sometimes, especially if I don’t put delays in clicking. It’s very strange that it crashes Dorico 90% of the time if it makes the clicks too fast. Even with delays, Dorico crashes sometimes when running the Keyboard Maestro macro.

I don’t believe it’s possible to do this with Dorico’s script/macro functionality.