Applescript - Click ok to clear window

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

  1. macrumors newbie

    Joined:
    Feb 8, 2010
    Location:
    Costa Del Manchester, UK
    #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

    Joined:
    Feb 1, 2009
    #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

    Joined:
    Feb 1, 2009
  4. thread starter macrumors newbie

    Joined:
    Feb 8, 2010
    Location:
    Costa Del Manchester, UK
    #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

    Joined:
    Feb 1, 2009
    #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. thread starter macrumors newbie

    Joined:
    Feb 8, 2010
    Location:
    Costa Del Manchester, UK
    #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

    Joined:
    Feb 1, 2009
    #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

    Joined:
    Feb 1, 2009
    #8

Share This Page