Auto-close a window

Using Acorn, this window pops up periodically. I was wondering if there is a way craft up an action to close this window when it appears. One problem I see is that the window appears to have no title.

Ideas? (see the actual graphic below)

Hey Ed,

There’s not a good way to do that, because you cannot hook into OSX and watch for open window events.

You’d have to create a macro that periodically scanned for this window – either with a Find Image on Screen action, or perhaps System Events (if System Events can see the window).

That is if Keyboard Maestro cannot see that window, and I’m guessing this is the case due to the type of window (dialog).

A macro constantly scanning for this dialog would be obtrusive and processor intensive.

-Chris

You can trigger on window change events.

But then you’d still have to use Find Image on Screen every time the window changed and I really wouldn’t recommend that.

OK guys… maybe I’ll craft something that, when I see the dialog, I can initiate with a hotkey.

… Thanks for the input.

Ah. I forgot about that.  :smiley:

Ed – try running this AppleScript from the Script Editor.app when that dialog is open in Acorn:

set yourProcessName to "Acorn"

tell application "System Events"
  tell application process yourProcessName
    properties of every window
  end tell
end tell

If you find something unique in the properties you can use the The focussed window title changes trigger in combination with an AppleScript.

System Events can probably see the text in the window, although it might take some detective work to get to it.

So. If you really want to automate this it is probably possible.

-Chris

OK Guys, finally got around to this. In an effort not to appear too lazy, this is what I came up with after running the script while that window was open. Not sure of (1) trigger, (2) how to capture the trigger (3); purpose of the apple script (to capture the trigger; to kill the window;

I get the feeling there is something here. but formally pulling it all together - not sure on that one.

And the window creating the event (I believe) looked like this.

Hey Ed,

The purpose of the AppleScript was to get information about the window in question to use elsewhere.

Since the subrole of the window is AXDialog you can do something like this:

----------------------------------------
tell application "System Events"
  tell application process "Acorn"
    tell front window
      if its subrole is "AXDialog" then
        tell button "Cancel"
          perform action "AXPress"
        end tell
      end if
    end tell
  end tell
end tell
----------------------------------------

The trouble is that there could be other alerts that you want to ignore.

I would try to tie to the text in the window, but you’ll have to do some more detective work to figure out how to get it.

I’d try this and look for “static text”.

tell application "System Events"
  tell application process "Acorn"
    tell front window
      UI elements
    end tell
  end tell
end tell

If you want a better tool for figuring this out try the UI Browser demo.

If you have Xcode installed you can also use the Accessibility Inspector.app.

-Chris

Thanks Chris for the reply.

Running the script, I came up with the static text of "Apply Operation?" which one I would like to ultimately use to confirm that this is the window that I would like to shut. Unfortunately, I am just not clear on the Applescript source code that would perform that. I searched around, the internet but did not find any such examples.

The Initial general dialog dismiss script you provided seems to work just fine, but I agree that targeting this one type of alert is what i would really like to do, not kill all alerts generated in Acorn. I will keep looking around, but if there is a simple command off the top of your head you can provide to target the one alert, please pass along.

Also, I am not clear on when to execute this operation. I would think it would be when there is any new window opened as a new front window in the Acorn application. But I do not see a specific activation call for that event.

Hey Ed,

This just builds on previous work:

----------------------------------------
tell application "System Events"
  tell application process "Acorn"
    tell front window
      if its subrole is "AXDialog" then
        if (get its static text) = "Apply Operation" then
          tell button "Cancel"
            perform action "AXPress"
          end tell
        end if
      end if
    end tell
  end tell
end tell
----------------------------------------

Use a Focussed Window Changes trigger. There are 4 types to choose from.

-Chris

Hey Chris,

The original macro kills the alert with no problem as a standalone script, but the latest one where you added the static text if statement does not.

I am wondering if the fact that there are 3 lines of static text, maybe the "get its static text" statement is either evaluating all lines of static text at once (or the wrong line?).

With regard to the trigger, I am not having any luck with the focused window choices. (please see attached screenshot). None of them seems to initiate the Applescript. Is there another way to trigger off of a new window is being opened within an application?

Also here is the output from The UI Browser app.

And if I ran this script (with the print statement added), it prints the various text of the dialog box.

1 Like

Hey Ed,

Change:

if (get its static text) = "Apply Operation" then

To:

if (get its static text) contains "Apply Operation" then

As for the trigger – it looks like Keyboard Maestro cannot see the Alert window.

System Events sees it, but I’m not certain how to work a trigger for that. (Peter?)

-Chris

Hi Chris,

Just some comments on the latest.

When I comment out the lines (as seen it the attached) it closes the alert.
However, if the lines are not commented out, and the script is executed, then there is no error codes, however, the alert simply does not close.

Sorry for all the trouble. Obviously this is an issue that is may be arguably too far off the beaten path.

In an effort to simplify the issue, I have no particular problem killing the alert in a broad sense, using the script that works to kill all the alerts (I can limit that to when i am just using Acorn).

I just need to figure out a usable trigger

(by the way, UI Browser you recommended worked very well...

Hey Ed,

At $55.00 U.S. UI Browser is fairly expensive, but it has saved me hours of time and was well worth the investment.

It’s a best-of-breed utility.

-Chris