On Jun 07, 2014, at 13:03, Robert Cuilla <email@hidden> wrote:I am under the gun to list only certain contacts in “Contacts” by using a script. For example, script “a” would present a list in a window on the screen of all contacts whose last name starts with the letter A.
Can anyone provide me with a little guidance or direction for such a script?
______________________________________________________________________
Hey Bob,
I don't see any way offhand to alter the sort in Contacts or produce a Smart-Group, but I can think of a couple of approaches.
Tested on OSX 10.9.3.
------------------------------------------------------------------------------------------- # Grab the info you want and display in TextEdit or other secondary app OR in a choose from dialog. # Choose-from option NOT in script. ------------------------------------------------------------------------------------------- set contactList to {}
set AppleScript's text item delimiters to tab
tell application "Contacts" set _group to people whose last name starts with "a" repeat with i in _group set _contact to contents of i set _record to {last name, first name, organization, value of (emails whose label contains "work")} of _contact set end of contactList to (item 1 of _record) & ", " & tab & (item 2 of _record) & tab & (items 3 thru -1 of _record) as text end repeat end tell
set AppleScript's text item delimiters to linefeed set contactList to contactList as text
set contactList to do shell script "column -s ' ' -t <<< " & quoted form of contactList
tell application "TextEdit" activate set newDoc to make new document with properties {text:contactList} tell text of newDoc set font to "Menlo" set size to 14 end tell end tell -------------------------------------------------------------------------------------------
Always backup your contacts before experimenting with adding/deleting items.
Delete in the case below is non-destructive and simply removes contacts from the group (not from the database altogether).
------------------------------------------------------------------------------------------- # Create a new group in Contacts with your specified members: ------------------------------------------------------------------------------------------- tell application "Contacts" set contactsToAdd to people whose last name starts with "a"
if length of contactsToAdd > 0 then
if (group "New_Sort" exists) = false then set newGroup to make new group with properties {name:"New_Sort"}
tell newGroup save set selected of it to true end tell
else
tell group "New_Sort" if selected of it = false then set selected of it to true if (count of its people) > 0 then delete every person of it save end if end tell
repeat with i in contactsToAdd add i to group "New_Sort" end repeat
save group "New_Sort"
end if end if end tell -------------------------------------------------------------------------------------------
-- Best Regards, Chris
|