Find and replace suffix field in the Address Book

Here’s my first foray with a script for finding a character in the address book and removing it. Several years ago an iOS app populated the suffix field with an Apple character for iPhone users. This functionality became part of iOS 6.0 with a iPhone field. I want to remove the Apple character from my Address book with over 2000 contacts.


tell application "Address Book"
	repeat with i from 1 to (count every person)
		set suffixProperties to properties of suffix of person i
		repeat with j from 1 to (count of suffixProperties)
			if value of item j of suffixProperties contains "" then
				set value of item j of phones of person i to ""
				log person
			end if
		end repeat
	end repeat
	save
end tell

This script complies; yet throws an error on “set suffixProperties to properties of suffix of person i.”

Please let me know if you have any ideas to achieve this goal in Applescript. I am not looking for vcf export solution; find and replace.

Hi neville310,

I don’t have a solution, but what system are you running?

gl,
kel

Hi. Suffix is a property; it doesn’t possess any. Try this:


tell application "Contacts"
	delete (people whose suffix contains "")'s suffix
	save
end tell

edit: Oops. I originally only skimmed the example code for intent. Based on Nigels observation, I’ve updated my method.

Hi Marc.

Although neville310’s script seems to be trying to delete phone numbers, his accompanying explanation says he wants to remove Apple characters from the suffixes. He shouldn’t try your script unless he definitely wants to lose the numbers!

Edit: Here’s a script which removes Apple characters from suffixes. if a suffix consists solely of an Apple character, it’s cleared by being set to ‘missing value’ instead.

tell application "Contacts" to set theSuffixes to suffix of people

set astid to AppleScript's text item delimiters
repeat with i from 1 to (count theSuffixes)
	set thisSuffix to item i of theSuffixes
	if (thisSuffix contains "") then
		if (thisSuffix is "") then
			set newSuffix to missing value
		else
			set AppleScript's text item delimiters to ""
			set tis to thisSuffix's text items
			set AppleScript's text item delimiters to ""
			set newSuffix to tis as text
		end if
		tell application "Contacts" to set suffix of person i to newSuffix
	end if
end repeat
set AppleScript's text item delimiters to astid

tell application "Contacts" to save