• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: a bit of Help on Contacts (addressBook): Solved Partially
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a bit of Help on Contacts (addressBook): Solved Partially


  • Subject: Re: a bit of Help on Contacts (addressBook): Solved Partially
  • From: TS Kamath <email@hidden>
  • Date: Tue, 20 Jan 2015 22:28:49 +0530

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.

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 {}
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

the following is the full Script.. I have partially achieved what i planned.. Like Takaaki & other have said.. I have bounded within the limitation set by Apple..

-- 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.. 

Regards & Thanks

Srikanth Kamath
http://tskamath.pactindia.net


On 20-Jan-2015, at 10:24 am, TS Kamath <email@hidden> wrote:

after a few trails and thinking out of the box.... its possible to get to group through Group ID

set theList to {}
tell application "Contacts"
-- 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"}, {}

set allPeople to people
set myMac to {}
repeat with theItem in allPeople
set tmpData to group of theItem
if tmpData does not contain {group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"} then
set end of myMac to theItem
else
-- set end of myiCloud to theItem
-- Note: set myiCloud to people of group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup" is much faster
end if
end repeat
set myiCloud to people of group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"
log myMac
log (count of myMac)
end tell

would it be possible to do this better..? any suggestion or sample code would help..

repeat with theItem in allPeople
set tmpData to group of theItem
if tmpData does not contain {group id "4CD38B69-B6D7-4354-B9FA-4D450CB84424:ABGroup"} then
set end of myMac to theItem
end if
end repeat


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >a bit of Help on Contacts (addressBook) (From: TS Kamath <email@hidden>)
 >Re: a bit of Help on Contacts (addressBook) (From: TS Kamath <email@hidden>)
 >Re: a bit of Help on Contacts (addressBook) (From: TS Kamath <email@hidden>)

  • Prev by Date: Yosemite application script problem
  • Next by Date: Re: JavaScript for automations: bug or correct behavior
  • Previous by thread: Re: a bit of Help on Contacts (addressBook)
  • Next by thread: JavaScript for automations: bug or correct behavior
  • Index(es):
    • Date
    • Thread