Applescript to close box by hitting ok automatically

0

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.

Andy

Posted 2013-11-19T04:35:18.413

Reputation: 1

Answers

0

Try:

set resultDialogReply to display dialog "Close after 5 seconds..." giving up after 5

adayzdone

Posted 2013-11-19T04:35:18.413

Reputation: 592

0

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.

Lri

Posted 2013-11-19T04:35:18.413

Reputation: 34 501

@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 – 2015-09-20T23:39:13.447

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 – 2013-11-26T12:05:25.173