PDA

View Full Version : Applescript handling of buttons in dialog boxes




petron
Oct 25, 2010, 12:26 PM
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"
activate
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 ?

b.r.
/petron



numlock
Oct 25, 2010, 04:23 PM
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"
activate
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 ?

b.r.
/petron

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

ShinyDren
Oct 25, 2010, 07:06 PM
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.
http://pfiddlesoft.com/uibrowser/
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. :o

Good luck

petron
Oct 26, 2010, 02:04 AM
Thanks for input,
I tried to use a short cut command and it works fine.
/petron

larkost
Oct 26, 2010, 11:37 PM
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):

http://www.mactech.com/articles/mactech/Vol.21/21.10/ScriptingAddressBook/index.html