How to detect and respond to error message in an application

I've written a macro that uses the Embrilliance embroidery software to convert an embroidery file into ten different formats. Everything works fine, except that if a file has too many colors, one of the conversions will pop up an error message in a window. The window automatically has focus, and the "OK" option is already highlighted, so all I need to do is press RETURN to acknowledge the error and continue on.

If I press RETURN manually quickly enough while the macro is running, the window will clear and the macro will continue on its merry way. But if I'm not watching it, the macro will quit after a second or two because the menu selection needed for the next step isn't available.

I know exactly when in the process the error will occur if it does occur, so I was wondering if there was a way to have the macro watch for the error window to pop up and press RETURN to clear it. I've included a picture of the error message in case my description was unclear. Thanks!

I figured out a way to do it. For the "If Then Else" action, one of the available conditions is whether or not the display contains a particular image. So at the part of the macro where the error would pop up, I check whether the error window is on the screen. If it is, I send a RETURN keystroke. If not, no action is taken.