1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Applescript - Click ok to clear window

Discussion in 'Mac Programming' started by Hayezy, Oct 11, 2010.

  1. macrumors newbie

    #1
    Being new at applescript I'm struggling with the actual commands I need to use to get applescript to click "OK" to clear this pop-up window.

    I'm trying to use click button "OK" of window "alert" but I'm getting no where,
    can anyone help?

    Screen shot
    [​IMG]
     
  2. macrumors 6502

    #2
    Normally use System Events, but I'm not sure how you reference a popup that isn't a sheet (like a drop down dialog from the window title-bar.
    ie.
    Code:
    tell application "System Events"
    	tell process "Finder"
    		click (button "OK" of sheet 1 of window 1)
    	end tell
    end tell
    
    But in your case there is no sheet and no window, although you could start by trying "frontmost window". Or if you're in OSX 10.4 or later, try recording it with Automator and see what script is produced.
     
  3. macrumors 6502

  4. macrumors newbie

    #4
    Cheers for the help, but I think I might need pointing in the right direction still.

    This is what I have so far

    Code:
    tell application "Finder"
    	try
    		mount volume "afp:/XXXX:XXXX@server/server_share"
    		tell application "System Events"
    			tell process "Finder"
    				keystroke return
    			end tell
    		end tell
    	end try
    end tell
    Any pointers, or am I completely wrong?
     
  5. macrumors 6502

    #5
    Looks good, although you maybe want a delay after the connection attempt
    or put the tell application "System Events" after an on error
    just before the end try, ie.

    Code:
    tell application "Finder"
    	try
    		mount volume "afp:/XXXX:XXXX@server/server_share"
    	on error
    		tell application "System Events"
    			tell process "Finder"
    				keystroke return
    			end tell
    		end tell
    	end try
    end tell
    Can't be sure if any connection failure is regarded as an error, so you may need to test.
    Otherwise replace the "on error" with a "delay 5" or "delay 60", or however long (in seconds) you are comfortable with, just to give the mount long enough to fail and produce the dialog box.
     
  6. macrumors newbie

    #6
    Both of those are a "no go" I'm afraid, script debugger just sits and spins until the dialogue is cleared manually. :mad:
     
  7. macrumors 6502

    #7
    I'm getting nowhere as well.

    Can't work out from the Finder Dictionary what the dialog might be referenced as, I suppose we could try 'dialog' - back to my first script clicking button "OK".
     
  8. macrumors 6502

    #8

Share This Page