Mac Auto select in dialog box with Applescript

njentzsch

macrumors newbie
Original poster
Jul 30, 2010
2
0
I'm trying to write a very simple Applescript that will automatically press the return key on a dialog box. I tried this:

Code:
tell application "Address Book"
	keystroke return
end tell
but get the error: Address Book got an error: Can’t get keystroke "*,

Can someone help a real neophyte with this? It's just the dialog box that comes up when a contact is imported into the Address Book and the button that is highlighted is either "Add" or "Import". Either way I just want to select it with Return!!

Thanks, Nancy
 

ergdegdeg

Moderator emeritus
Oct 13, 2007
1,628
0
keystrokes are system events so you have to use
Code:
tell application "System Events" to keystroke return
Or, if you want Address Book to activate before that:
Code:
tell application "Address Book" to activate
tell application "System Events" to keystroke return
 

njentzsch

macrumors newbie
Original poster
Jul 30, 2010
2
0
Solved

Here's what worked:
Code:
tell application "Address Book"
	activate
	tell application "System Events"
		keystroke (ASCII character of 13)
		
	end tell
end tell
Thanks for the replies.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.