the following is faster approach, used the learning from Hiroto, japan on using list.. with the modification, I get the contacts in iCloud (1900) and On My Mac(3800) in less than 1 minute.
-- use the following to find the group id of the default groups, i.e. “iCloud” or “On My Mac"
-- set myiCloud to name of people of group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"
-- log name of groups of people as list
-- -- > {"card"}, {}
-- log groups of people as list
-- -- > {group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"}, {}
-- log id of groups of people as list
-- -- > {"4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"}, {}
tell application "Contacts"
--set idListiCloud to id of people of group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"
set idListMac to {id of people, id of groups of people, name of people}
set myiCloud to {}
set myMac to {}
set nameiCloud to {}
set nameMac to {}
set theList to {}
repeat with itemCnt from 1 to count of (idListMac's item 1)
if ((idListMac's item 2)'s item itemCnt) contains "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup" then
-- set end of myiCloud to {(idListMac's item 1)'s item itemCnt, (idListMac's item 3)'s item itemCnt}
set end of myiCloud to (idListMac's item 1)'s item itemCnt
set end of nameiCloud to (idListMac's item 3)'s item itemCnt
else
set end of myMac to (idListMac's item 1)'s item itemCnt
set end of nameMac to (idListMac's item 3)'s item itemCnt
end if
end repeat
set myaddList to {}
if (count of nameMac) is greater than (count of nameiCloud) then
repeat with itemCnt from 1 to count of nameMac
if nameiCloud does not contain nameMac's item itemCnt then
set myaddList to myaddList & (every person whose id is myMac's item itemCnt)
end if
end repeat
if length of myaddList is not 0 then
-- make a group --
if not (group "contacts not iCloud" exists) then
make new group with properties {name:"contacts not iCloud"}
end if
save
-- add person to default Account -- iCloud in my case
repeat with theItem in myaddList
-- set tmpData to (properties of theItem whose value is not missing value)
-- not implemented all of the properties of person in On My Mac --
set tmpData to theItem's {first name, last name, organization} -- emails, phones, address}
set thePerson to make new person with properties ¬
{first name:tmpData's item 1, last name:tmpData's item 2, organization:tmpData's item 3}
set tmpEmail to every email of theItem
set tmpPhone to every phone of theItem
set tmpAddress to every address of theItem
tell thePerson
repeat with theItem in tmpEmail
set tmpData to {theItem's label, theItem's value}
make new email at end of emails with properties {label:tmpData's item 1, value:tmpData's item 2}
end repeat
repeat with theItem in tmpPhone
--- set tmpData to {theItem's label, theItem's value}
make new phone at end of phones with properties {label:theItem's label, value:theItem's value}
end repeat
repeat with theItem in tmpAddress
make new address at end of addresses with properties ¬
{label:theItem's label, street:theItem's street, city:theItem's ¬
city, state:theItem's state, zip:theItem's zip}
end repeat
end tell
add thePerson to group "contacts not iCloud"
end repeat
save -- "Contants"
end if
else if (count of nameiCloud) is greater than (count of nameMac) then
-- not implemented: condition when count is same but contents may be diffrent
— further this implementation is partial.. I am still not able to add person to "On My Mac"
-- workaround is
-- select the contacts in "contacts not OnMyMac" and drag them to "On My Mac"
repeat with itemCnt from 1 to count of nameiCloud
if nameMac does not contain nameiCloud's item itemCnt then
set myaddList to myaddList & (every person whose id is myiCloud's item itemCnt)
end if
end repeat
if length of myaddList is not 0 then
if not (group "contacts not OnMyMac" exists) then
make new group with properties {name:"contacts not OnMyMac"}
end if
save -- "Contants"
repeat with theItem in myaddList
add theItem to group "contacts not OnMyMac"
end repeat
save -- "Contants"
end if
end if
end tell
any advise and comments is highly appreciated..