Script for copying the value of a field to note in address book...

Hi! :slight_smile:

I just realized that iPhone address book does not show “spouse” and “child” field.
I am doing a lot of work with this information on the go so I need to see their names somehow.

One way that I thought possible was to put the names in the note field since iPhone at least shows “note” from Address book.
I briefly thought about copying each one manually but with over 1000 names… No way.

Is there a script that I can use to do this? Copying the names from “spouse” and “child” to put it in “note”?
It would be nice if it can be flexible enough to copy any field to “note.”

Thank you very much!

*I tried to search it but the search engine is a little funky.

I am not the Address Book expert. But I believe this will work. Unfortunately, other things, like websites, are also considered as “related names”. Also, I got a “missing value” error when it tried to do a website one. So I tested for only “spouse” or “child”.

Also I couldn’t figure out how to find for only people who had related names. So it is looping thru every person; not very efficient.

So, the below can be considered a start. It worked for me; but I have few entries.


tell application "Address Book"
	set people_ids to people
	
	repeat with person_id in people_ids
		tell related names of person_id
			set related_labels to label
			set related_names to value
		end tell
		
		-- Loop thru related names (if any)
		set cnt to count (related_labels)
		if cnt > 0 then
			
			repeat with i from 1 to cnt
				set counter to i
				set label_txt to item i of related_labels
				set name_txt to item i of related_names
				if label_txt is "spouse" or label_txt is "child" then
					try
						set note of person_id to (note of person_id) & (linefeed & label_txt & ": " & name_txt)
					end try
				end if
			end repeat
			-- end related names loop
		end if
	end repeat
	-- end people loop
	save
end tell

Maybe I have too many entries in Address Book.

When I ran the script, it got hung.

I just have to run the script, right? Thanks~ :slight_smile:

Yes. I just ran it. I only have 130 people in my Address book, so it only took a few seconds. I was kind of hoping someone who knows Address Book (or AppleScript) better than I could offer some optimization tips. For one thing, it would be great to find only those who had related names first.

Also, as is it has no way to know if you’ve already done it on a particular person’s note. So it would add them again. I suppose it could test to see if the note already contains “spouse:” or “child:”

Hi,

Maybe you can create an intelligent group in AddressBook, for all the people with “spouse” or “child” and then modify the applescript to check only the people in that group ?

Hope it works,

Nicolas