Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

petron

macrumors member
Original poster
May 22, 2009
95
0
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.


Code:
#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
 
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.


Code:
#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
 
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. :eek:

Good luck
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.