Has Sur Changed Contacts object model or syntax?

Hi All,

I’ve had this script for approx 10 years. Sadly my 2012 MacBook pro died (may it rest in pieces) and I reluctantly laid out cash to get a new one. It’s a new M1 MacBook pro that runs 11.01.

The script allows me to personalise address labels for my Christmas cards, including spouses and children in the address, it worked perfectly without fail every year. However it appears that the “contacts” part of the script no longer works, the list item totalAddresses appears empty before it is passed to word. I just can’t figure out why.

Anyway here’s the script…


tell application "Contacts"
	
	
	set theContacts to the selection
	set totalAddresses to {}
	set counter to 0
	set noPeople to count of theContacts
	if noPeople is greater than 21 then
		display dialog "Maximum Number is 21" & return & "you have " & (noPeople - 21) & " too many"
	end if
	repeat with thisPerson in theContacts
		set counter to counter + 1
		set thefirstName to first name of thisPerson
		set thelastName to last name of thisPerson
		set relCount to count of related names of thisPerson
		
		set relNames to value of related names of thisPerson
		repeat with RName in related names of thisPerson
			set relType to label of RName as text
			if relType is "spouse" then
				set thefirstName to thefirstName & " & " & value of RName
			end if
			if relType is "partner" then
				set thelastName to thelastName & " & " & value of RName
			end if
		end repeat
		if relCount is greater than 1 then
			set thelastName to thelastName & " & Family"
		end if
		
		set theName to thefirstName & " " & thelastName
		
		repeat with noAddress in addresses of thisPerson
			set typeAddress to label of noAddress as text
			
			if typeAddress is equal to "home" then
				set theStreetstring to street of noAddress
				set theStreet to paragraph 1 of theStreetstring
				try
					set theStreet2 to paragraph 2 of theStreetstring
					set theStreet to theStreet & return & theStreet2
				end try
				try
					set theStreet3 to paragraph 3 of the theStreetstring
					set theStreet to theStreet & return & theStreet3
				end try
				try
					set theStreet4 to paragraph 4 of the theStreetstring
					set theStreet to theStreet & return & theStreet4
				end try
				
				if city of noAddress exists then
					set theCity to city of noAddress
					set theStreet to theStreet & return & theCity
				end if
				
				
				if state of last address of thisPerson exists then
					set theState to state of noAddress
					set theStreet to theStreet & return & theState
				end if
				
				set theZip to zip of noAddress
				
				set theaddress to theName & return & theStreet & return & theZip
				copy theaddress to the end of totalAddresses
			end if
		end repeat
	end repeat
	
	
	
	tell application "Microsoft Word"
		set Cellcounter to 0
		activate
		create new document attached template "Macintosh HD:Users:Will Fox:Documents:J8160template.dotx"
		
		
		set theTable to table 1 of active document
		
		set rowCount to (count rows of theTable)
		
		
		
		set columnCount to (count columns of theTable)
		
		display dialog columnCount
		
		repeat with rr from 1 to rowCount
			
			repeat with cc from 1 to columnCount by 2
				set Cellcounter to Cellcounter + 1
				set aCell to cell cc of row rr of theTable
				set aRange to create range active document start (start of content of text object of aCell) end ((end of content of text object of aCell) - 1)
				try
					if (cc / 2) is less than or equal to noPeople then
						set the content of aRange to item Cellcounter of totalAddresses
					end if
				end try
			end repeat
		end repeat
	end tell
end tell

Anyway, thanks for looking. It’s too late for this year as I just used the inbuilt contacts printing option and inelegantly hand wrote the extra stuff. Oh the shame :relaxed:.

Cheers,

Will.

I think the problem is:


		repeat with noAddress in addresses of thisPerson
			set typeAddress to label of noAddress as text
			--> _$!<Home>!$_
			if typeAddress is equal to "home" then

I get a list if I change the last line to:


			if typeAddress contains "Home" then

You absolute star! It works again.

Thank you.