Sunday, June 16, 2019

#1 2019-05-31 04:58:27 pm

Registered: 2019-05-05
Posts: 1

Alert pop up window: unexpected delay in the closing action.


Currently, I'm developing a script to automate some processes within a non scriptable application that it is used by my company.

During the workflow of this application, there is an alert pop up window which prompts the user whether to close the window through clicking the button "close window"  or instead, clicking the button  "Don't close window" to continue in that pop up window.

By default the action selected is the "close window” button and  if the user hits the enter or the space bar, the close action takes place immediately.

I was able both to target correctly every UI element engaged in that process and to close the window programatically.

The issue is that even though the alert pop up window at the end gets closed, this action does not happen immediately, instead it takes like 10 seconds to perform the action.

I could not find the reason why of such delay.

The affected buttons ( “Close window" and  "Don't close window”) are located within a sheet element.

These are the ways I tried so far to perform the alert pop up window close action but neither of them addressed the mentioned delay issue:

- set button "Close Window” focused to true

- click button "Close Window”

- keystroke SPACE

- keystroke RETURN

- key code 49 -- 76-- 36

I've even tried to wrap the closing action in the following block code:

ignoring application responses
   -- Closing window code goes here
end ignoring

Everything tried got the same unexpected delay in performing the close action.

I wonder if there is a way to prevent that the alert pop window shows up or at least being able to reduce the time that takes the close action to get completed.

Thank you all in advance.



#2 2019-06-10 12:15:40 pm

Registered: 2019-03-03
Posts: 145

Re: Alert pop up window: unexpected delay in the closing action.

The information you provided is not enough to help you. But approximately I can say what the problem may be:

When a certain command is executed, the AppleScript interpreter searches for the "owner" of the command, that is, an object or app that "understands" this command. If you do not help the interpreter to find this application, then it searches for it in several locations of the hard disk itself. Therefore, it is always better to indicate the "owner" of the command explicitly. For example:


tell application "Microsoft Excel" to activate
tell application "System Events" to tell application process "Microsoft Excel"
tell window 1
-- Closing window code goes here
end tell
end tell

Here owner of commands is window 1 of application process "Microsoft Excel" of application "System Events".

Maybe simpler too:


tell application "Microsoft Excel"
-- Closing window code goes here
end tell


You can see object model of application 1) using app "Object Browser" (paid), 2) you can read scripting dictionary of application, 3) using Script Debugger (paid, I use that) 4) using test script similar to following:


tell application "Microsoft Excel" to activate
tell application "System Events" to tell application process "Microsoft Excel"
UI Elements
end tell

AND NOTE: NO NEED for scriptable applications KEYSTROKE of SYSTEM EVENTS and SYSTEM EVENTS itself.

So, you need to determine which object your popup window (which is object too) belongs to, and then "tell" this object to "close the window". Unfortunately, you did not indicate which application you are using, otherwise I would tell you exactly what kind of object it is.

Automator's record option is very usefull for finding proper obects too

Last edited by KniazidisR (2019-06-10 01:19:54 pm)

macOS Mojave -- version 10.14.4
Safari -- version 12.1



Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)