PDA

View Full Version : Applescript - Click ok to clear window




Hayezy
Oct 11, 2010, 07:14 AM
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
http://i97.photobucket.com/albums/l226/hayezy/Screenshot2010-10-11at130821.png



BertyBoy
Oct 11, 2010, 10:47 AM
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.
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.

BertyBoy
Oct 11, 2010, 01:04 PM
Even easier than I thought:

http://discussions.apple.com/thread.jspa?messageID=12315516�

Hayezy
Oct 12, 2010, 01:36 AM
Cheers for the help, but I think I might need pointing in the right direction still.

This is what I have so far

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?

BertyBoy
Oct 12, 2010, 03:48 PM
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.

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.

Hayezy
Oct 13, 2010, 01:33 AM
Both of those are a "no go" I'm afraid, script debugger just sits and spins until the dialogue is cleared manually. :mad:

BertyBoy
Oct 13, 2010, 02:15 PM
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".

BertyBoy
Oct 13, 2010, 03:39 PM
Seems to have been an issue for a LONG time ...

http://macscripter.net/viewtopic.php?id=10583