Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create a script that automatically closes a popup box that opens approximately every 55 - 65 seconds. Once the box opens, you merely hit OK (within the box) and it closes.

I created an applescript application but found that I still need to hit manually run the script for it to work.

on idle
    tell application "XYZ"
    tell application "System Events" to key code 36
    end tell
    return 65
end idle
  1. Instead of specifying a time, in this case 65 seconds, can I not say; if the dialog box opens click the OK button. In that way anytime the box opens, it will be closed without disturbing me whilst I work on the application.
  2. I'd really only like the script to be activated at the time, the window/popup shows up and not before.
  3. The script should be active, whilst I use the application (XYZ). How long I will use XYZ will vary.
share|improve this question


set resultDialogReply to display dialog "Close after 5 seconds..." giving up after 5
share|improve this answer

You might just run the loop every second or so:

    if (exists application "XYZ") then
        tell application "System Events" to tell process "XYZ"
            if exists (button "OK" of window "Window Title") then
                click (button "OK" of window "Window Title")
            end if
        end tell
    end if
    delay 1
end repeat

If the window does not have a title, try replacing window "Window Title" with window 1, or run tell application "System Events" to tell process "XYZ" to properties of windows to see if the window can be identified some other way.

share|improve this answer
Thanks for the feedback. Deleted other post.Made the following amendments:1. added in window 1 and I get an error - Can’t continue exists." number -1708 – Andy Nov 26 '13 at 12:05
@Andy Error -1708 is usually because the AppleScript excution environment does not know what context to send/call the method to. The context is specified by "tell application XYZ" / end tell. Alternatively, you need to specify the keyword my in from of the function being called: my computeFilesMissing – David Andreoletti Sep 20 '15 at 23:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .