GUI scripting - How to tell System Event is complete

I have a GUI script that selects some menus in an application (Quark). It looks like the code runs asynchronously with the UI events though… that is the code sends the menu selections to Quark and then the AppleScript continues to execute even though Quark may not have processed the menu events yet. I need to have the events finish before the AppleScript continues. I can put a delay in after sending the menu events and this seems to bypass the problem b/c the menu events have finished processing by the time the delay ends, but this isn’t very elegant. Anyone have an idea how to tell if the “System Events” menu selections have finished processing?

tell “system events”
tell application “quark”
select some menu items
delay 1 – rather than delay, need a way to figure out if the menu actions have completed
end tell
end tell

I am afraid that GUI scripting isn’t a very controllable mechanism that can be easily verified - unless you’d check the result of every single step in Quark.
Your own solution would be better.
Don’t use “delay” command this way - it will stop the process you 'd want to proceed and takes a lot of processor load.


tell "system events"
    tell process "quark"
        select some menu items
       tell me to do shell script "sleep 1"  --> have the script (not process Quark) wait 1 seconds & a free ride for you CPU
    end tell
end tell