How can I script the pressing of the default button, the button with the focus?
Alternately, how can I script the pressing of the OK button?
(keystroke return does not work)
I’d need more details, since done properly, “keystroke return” should work. Bear in mind if you’re trying to do it too quickly, you may need to use “delay 0.5” just before the keystroke to give the dialog time to appear. The reason it fails is because the keystroke is happening before the button is available.
If it truly isn’t working however, in many applications each button has a keyboard shortcut assigned. If you can figure out what that keystroke is (assuming it exists), then you could script that.
Just tossing out ideas, not alot to go on.
Thanks for your ideas Kevin.
I included a delay of 1, so it isn’t that.
I notice that in the posted code snippets the word “return” is bolded, but when I paste into AppleScript Editor and compile it does not get bolded; it may a contextual issue, I don’t know.
Perhaps the solution is to send the keystroke for “return” or a CR. How do I find that?
Hi.
The forum displays code differently. In Script Editor, “return” will not compile bold. I think I am using the defaults, which display application keywords in blue and language keywords in bold blue - look in the editor’s preferences under “Formatting.”
Without seeing what you are trying to do, it’s difficult to know how to help. Maybe seeing a working example will help:
tell application "TextEdit"
activate
make new document with properties {text:"Click save test"}
delay 1
tell application "System Events"
keystroke "s" using command down
delay 1
keystroke "Click Save"
delay 1
keystroke return
end tell
end tell
If you want to close a dialog box after a few seconds so the script can continue, do this:
display dialog "3... 2... 1..." giving up after 3
Hope that helps. If it doesn’t, post the code you are having trouble with - it will make helping you easier.
j
Hello Tombeek
Which application is issuing the dialog ?
When it is AppleWorks for instance, some dialog take care of a
keystroke return (return is the predefined variable for ASCII character 13)
while with some others, the default button blinks but doesn’t do its duty.
It’s a matter of “new rules” not used.
Yvan KOENIG (from FRANCE samedi 14 octobre 2006 07:01:39)
I am scripting “Internet Connect”, entering an “Other” wireless netork name.
I’ve got it to the point of entering the network name correctly, and am now trying to close the dialog and quit the app.
Lucky for you I’m a bit of an insomniac, otherwise I wouldn’t be answering at almost 3:00 a.m.
I revisited the thread I previously pointed you to - http://bbs.applescript.net/viewtopic.php?id=17410 - and realized the script was incomplete. The problem is that although the “OK” button is blue, the focus is not yet on it. A couple of “keystroke tabs” will get you there.
I guess I didn’t think past (that thread’s) original question to get to the next step:
tell application "Internet Connect"
activate
tell application "System Events"
tell window 1 of process "Internet Connect"
click button "Airport" of tool bar 1
tell pop up button 1
perform action "AXPress"
click menu item "Other." of menu 1
set theName to "whatever"
keystroke theName
delay 1 --you might need this to prevent the next button click from happening too quickly
keystroke tab
keystroke tab
keystroke return
end tell
end tell
end tell
end tell
EDIT: While previewing this post, I realized that I didn’t tell Internet Connect to quit, you’ll need to add that. I could have fixed that faster than typing this, which just occurred to me, but I’m too sleepy to be sensible.:rolleyes:
Yes! Works great!
At this point quitting shouldn’t be difficult, but the lines I’ve put in do not work!
I’ve tried,
tell application “Internet Connect” quit end tell
but no go. I get error messages that look sensible, but I have no clue how to fix them.
Also, I have not found any help on getting the permissions right in Firefox to allow the presing of the “Open this Scriplet in your Editor:” link to do anything.
Thanks a million.
I’ve only used Firefox a couple of times (I needed it to set up my modem, which doesn’t like Safari.) I can’t even find that option.
Do you have UIElement Inspector? It makes GUI scripting a little less frustrating.
http://developer.apple.com/samplecode/UIElementInspector/index.html
Edit: I think you edited while I was posting. I’m guessing you’ll need a sufficient delay while the connection is being tried, but I haven’t tested that.