Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript not returning emails for Contacts - people

I am not sure why this isn't working as it retrieves people where I know there are emails associated with most of the people in contacts:


on cleanval(val)

local oval

set oval to null

if val is not equal to missing value then

set oval to val

end if

return oval

end cleanval


tell application "Contacts"

local results, cloop, ident

set results to {}

local G__6588

set G__6588 to people -- whose (first name contains "Frank")

repeat with G__6587 in G__6588

set cloop to properties of G__6587

set ident to {primary_department:null, first_name:null, name_suffix:null, middle_name:null, primary_company:null, primary_title:null, last_name:null, full_name:null}

set primary_department of ident to my cleanval(department of cloop)

set first_name of ident to my cleanval(first name of cloop)

set name_suffix of ident to my cleanval(suffix of cloop)

set middle_name of ident to my cleanval(middle name of cloop)

set primary_company of ident to my cleanval(organization of cloop)

set primary_title of ident to my cleanval(job title of cloop)

set last_name of ident to my cleanval(last name of cloop)

set full_name of ident to my cleanval(name of cloop)

local elist, eadd

set elist to {}

repeat with eml in (get emails of cloop)

set eadd to {email_type:null, email_address:null}

set email_type of eadd to my cleanval(label of eml)

set email_address of eadd to my cleanval(value of eml)

set end of elist to eadd

end repeat

set ident to ident & {email_list:elist}

set end of results to ident

end repeat

return results

end tell

MacBook Pro (Retina, 15-inch, Mid 2014), OS X Yosemite (10.10.3), null

Posted on Sep 1, 2015 4:56 AM

Reply
4 replies

Sep 1, 2015 11:55 AM in response to FrankCast

Hi,



tell application "Contacts"

repeat with peeps in people

repeat with emls in (emails of peeps)

log (get value of emls)

end repeat

end repeat

end tell

This script work because peeps it's a person object


-----

tell application "Contacts"

repeat with peeps in people

set theProps to properties of peeps

repeat with emls in (emails of theProps) -- no loop, because (emails of theProps) is empty

log (get value of emls)

end repeat

end repeat

end tell

This script gives no log, because theProps (the properties) does not contains any email object


---------------

So use --> repeat with eml in (get emails of G__6587) -- in your script , to get the email's address

Applescript not returning emails for Contacts - people

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.