Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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"
    activate
    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

2 Answers 2

Try:

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:

repeat
    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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.