Applescript handling of buttons in dialog boxes

Discussion in 'Mac Programming' started by petron, Oct 25, 2010.

  1. petron macrumors member

    May 22, 2009
    Malmo, Sweden
    Hi folks,

    I started to write a script that imports Vcards into the Address Book.

    The problem I have right now is how to handle the dialog box's buttons.
    As long as I want to simulate the default button all works fine.

    #open vcf file
    tell application "Address Book"
    	open "Users:minpc:Desktop:ha.vcf"
    	tell application "System Events"
    		keystroke return
    	end tell
    end tell
    How can I specify to activate different button then the default one ?

  2. numlock macrumors 68000

    Mar 13, 2006
    there are two solutions I see instantly.

    One would be to press number the correct number of times and the other would be to use the keyboard shortcut for the desired button
  3. ShinyDren macrumors member


    Jun 25, 2010
    Ambitoysterous, USA
    You can use code such as this (it also works with buttons):
    "tell radio group 1 of scroll area 2 of group 1 of splitter group 3 of window 1"

    The easiest way to get the exact info you need is by using a program called "UI Browser". It will create the exact code for you, and the installer includes some sample code scripts.
    It comes with a 30 day free trial, so you can test it to see if it helps you out.

    I think you have to have "Enable access for assistive devices" enabled in the Universal Access System Preference, but it has been a while so it might not be necessary. :eek:

    Good luck
  4. petron thread starter macrumors member

    May 22, 2009
    Malmo, Sweden
    Thanks for input,
    I tried to use a short cut command and it works fine.
  5. larkost macrumors 6502a

    Oct 13, 2007
    GUI scripting should only be used as a last resort (unless you are specifically doing Q/A on the software... and I assume you are not doing that for AddressBook).

    AddressBook provides a nice dictionary that you can use to access and manipulate the contents of the data store very nicely. To view it open the AppleScript Editor and select "Open Dictionary" from the File menu.

    There is even a MacTech article on it (just a google away):

Share This Page