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 {"[email protected]"} 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.
add
command to theapplication
object, whereas I directed it to theperson
object. That said, I don’t think that should make a huge difference. The biggest difference is your omission of thesave
command, 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 adelay
will 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:08process
objects are usually named the same as theapplication
that spawned it, but not always. It’s therefore more reliable to reference aprocess
by 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 appid
key form avoids triggering application launches that occur using itsnamed
key form. – CJK Aug 06 '20 at 23:52