I have a problem with my Contacts on Mac running Sonoma (14.3.1 ). I have used Outlook and it created a custom field named Outlook on some of my Contacts. I want to delete this contact field and all of its content on all the contacts that have it. In some instances Outlook even duplicated the Outlook field. I have over 3000 Contacts with this issue and fixing it one by one doe s not seem like a solution. The fleld (named Outlook) has a huge link text on it that starts with ms-outlook://people/.
Has anyone come across this or can point me in the direction of a script that can help me?
With any luck, if your spurious “Outlook” fields contain links, they’ll be represented by url objects in the Contacts app. A script will need to find any such objects whose label value is “Outlook” and delete them from the contacts containing them.
There are various ways to handle this. The script below should be fairly fast if you have over 3,000 contacts. If any “Outlook” fields remain after it’s run, we’ll need to identify what class of contact info’s actually involved.
tell application "Contacts"
-- These will be 3,000+ item lists.
script o
property contacts : {}
property urlLabels : {}
end script
set {o's contacts, o's urlLabels} to {it, label of urls} of people
repeat with i from 1 to (count o's contacts)
if (item i of o's urlLabels contains {"Outlook"}) then
set thisContact to item i of o's contacts
delete (thisContact's urls whose label is "Outlook")
end if
end repeat
save -- Save and make visible the changes.
end tell
missing value is the normal result of the save command and is perfectly OK. Are you getting it from anywhere else in the script? The corrected, working script is the one in post #2 above.
Yes. Post #3 quotes the original version of the script in post #2, in which I made a few errors. The post #2 script has since been corrected. Post #3 immortalises the original goofs.
Ok thanks using the correct one now.
It’s fair to say that I realise the URL are under label “other” and “home page” in my case (I have some 5k contacts, that needs to be adjusted, so getting it right is important).
How does the script change? Excuse my ignorance
Hi @adilif. Sorry for the slow reply. I’m preparing my house for some work next week.
If I’ve understood correctly, you want a version of the script which does exactly the same as above, but using Contacts’s predefined URL labels “other” and “home page” instead of sankaman’s custom label “Outlook”.
Contacts’s predefined labels are a bit strange in that their text in AppleScript is wrapped in special codes. So in a script, “other” and “home page” are represented by “_$!<Other>!$_” and “_$!<HomePage>!$_” respectively.
tell application "Contacts"
-- These will be 3,000+ item lists.
script o
property contacts : {}
property urlLabels : {}
end script
set {o's contacts, o's urlLabels} to {it, label of urls} of people
repeat with i from 1 to (count o's contacts)
set thisContact to item i of o's contacts
set theseLabels to item i of o's urlLabels
if (theseLabels contains {"_$!<Other>!$_"}) then delete (thisContact's urls whose label is "_$!<Other>!$_")
if (theseLabels contains {"_$!<HomePage>!$_"}) then delete (thisContact's urls whose label is "_$!<HomePage>!$_")
end repeat
save -- Save and make visible the changes.
end tell