Auto select in dialog box with Applescript

Discussion in 'Mac Programming' started by njentzsch, Jul 30, 2010.

  1. njentzsch macrumors newbie

    Joined:
    Jul 30, 2010
    #1
    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
     
  2. tinaCEO macrumors newbie

    Joined:
    Jul 30, 2010
    #2
    Use any debugging tool to find out where the error is. And how to resolve it.
     
  3. ergdegdeg Moderator emeritus

    ergdegdeg

    Joined:
    Oct 13, 2007
    #3
    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
     
  4. njentzsch thread starter macrumors newbie

    Joined:
    Jul 30, 2010
    #4
    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.
     

Share This Page