Using AppleScript, how can I tell Zotero has finished starting after being launched?

I have some AppleScript-based automation around Zotero on macOS. If the application is not running, I need to start it. For my environment and Zotero library contents, it takes significant time to finish loading, which means I have to make sure the rest of the automation workflow waits before it tries to communicate with the app. Currently I do that using a hardcoded wait, like this:

tell application "Zotero"
if it is not running then
launch
repeat until application "Zotero" is running
delay 0.5
end repeat
-- For me, Zotero takes a long time to load even after it's
-- launched. I haven't found a way to test it's done, so
-- all I can do is use a delay here & hope for the best.
delay 15
end if
end tell

I'd like to improve this by getting rid of the fixed number and doing something to detect that Zotero really has finished starting. So … is there a way to detect that Zotero has finished starting?

I know Zotero does not actually provide an AppleScript interface, and so this is perhaps more a question about the underlying framework used to create the Zotero app for macOS. The question may have a more general answer, like "this is how you should do it for any app on macOS".
Sign In or Register to comment.