I tried to re-jig the applescript from these two answers, but no dice. It seems to work if you're creating contacts at the same time, but not when finding existing contacts.
tell application "Contacts"
set thePersons to {"john@email.com"} as list
set theGroup to group "MyGroup"
repeat with thePerson in thePersons
delay 0.1
set theContact to (first person whose value of last email contains thePerson)
add theContact to theGroup
end repeat
end tell
The above runs without error, but nothing happens, no one is added. I'm not exactly sure what I'm doing wrong.
The goal is to produce an applescript where I can just provide a list of emails and it'll find/add them to a specified group.
addcommand to theapplicationobject, whereas I directed it to thepersonobject. That said, I don’t think that should make a huge difference. The biggest difference is your omission of thesavecommand, which is needed to make changes permanent. But I will run your script again and tell you what transpires. I did it the first time, but have forgotten. – CJK Aug 06 '20 at 22:55list. Besides not being necessary, it’s a fairly costly operation, which is why other languages type check before re-casting, but AppleScript, if I recall, doesn’t, and will actually perform a needless coercion. ⓶ There are specific instances where adelaywill be effective, and the reason why is always because the operation preceding it doesn’t return a value. Actually, it’s more accurate to say the operation is run asynchronously, so it doesn’t wait for a value to be returned. All our commands run synchronously so delays won’t help – CJK Aug 06 '20 at 23:08processobjects are usually named the same as theapplicationthat spawned it, but not always. It’s therefore more reliable to reference aprocessby the bundle identifier too, but it’s not as easy. There’s noprocess id ...key form, so one needs tofirst process whose bundle identifier = .... ⓹ Pro tip: using the appidkey form avoids triggering application launches that occur using itsnamedkey form. – CJK Aug 06 '20 at 23:52