Click button when dialog appears?

In the app Pixelmator Pro, a dialog (sheet, actually) appears when saving an edited JPG file. The default button is to Save As to create a Pixelmator pxm file, but I want to click "Overwrite" automatically since I just want to re-save the JPG.

I've set up a macro to click the button on a keystroke, but is there a way to just click this button when it (or its dialog) appears?

Try giving your macro a Focused Window trigger that changes when the focused window does and see if that doesn't do the trick. Be aware that if you go this route, you'll likely want to encase the macro in an If Then Else action that runs the macro when the Overwrite button is enabled and does nothing if it isn't, otherwise you will be notified by default that the macro failed every time the focused window changes and the dialog isn't present. Alternatively, you can also tweak the macro action settings to not notify you when the macro fails to find the Overwrite button from the circular gear icon in the top right corner of the relevant action.