How to move to the find field in Address Book ?

Hi,

I want to be able to move to the find field in my Address Book and select all adresses in case that a specific group was already selected. I found a thread in MacScripter that seemed to be the answer but it does not work. Maybe I am missing something. This is the script that I found, but I have to say that I don’t understand it really:

activate application "Address Book"
tell application "System Events"
	tell process "Address Book"
		set value of attribute "AXSelected" of row 1 of outline 1 of scroll area 1 of splitter group 1 of window "Address Book" to true
	end tell
end tell
tell application "Address Book"
	set selection to people whose name contains theSearchstring
	set sel to selection
end tell

I get this error message:

error “Erreur dans System Events : Il est impossible de régler window "Address Book" of process "Address Book" à true.” number -10006 from window “Address Book” of process “Address Book”

What is going wrong ?

Regards.

Robert Lespérance

Hi, Robert.

On my machine, the GUI Scripting part of the code succeeds in selecting the first “Group” in Address Book’s “Group” list, which is the “All Contacts” group. This group isn’t actually a ‘group’ in the AppleScript implementation, so you can get the same effect by setting the ‘selected’ property of all the real ‘groups’ to false! “All Contacts” is then selected by default.

It’s the second part of the script which fails for me because it tries to set Address Book’s selection to the reference ‘people whose name contains theSearchString’. It seems that Address Book will only accept a list, so you have to ‘get’ the list from the reference first. This can be done by swapping the words ‘sel’ and ‘selection’:

-- Tested with Address Book 5.0.3.

tell application "Address Book"
	activate
	set selected of groups to false -- Select the "All Contacts" group!

	set sel to people whose name contains theSearchstring
	set selection to sel
end tell

PS. I suppose one reason the System Events code doesn’t work for you could be that your Address Book window’s called “Carnet d’addresses”!