applescript search for person by email

Discussion in 'Mac Programming' started by mieslep, Oct 12, 2012.

  1. mieslep macrumors newbie

    Joined:
    Oct 12, 2012
    #1
    I am trying to get a set of Address Book "person" objects for those people with e-mails containing a specific string (e.g. "somedomain.com").

    As a proof of concept:

    Code:
    tell application "Address Book"
      repeat with thePerson in (every person where the value of its email contains "somedomain.com")
        display dialog "first=" & (first name of thePerson) & " last=" & (last name of thePerson)
      end repeat
    end tell
    However, this search doesn't work...and I can't figure out why not! I can search for people with "first name" and such, it seems to be related to not correctly be searching into the "emails" collection. "where the value of its first email" does return a result, but isn't functionally what I want to do...
     
  2. kryten2, Oct 12, 2012
    Last edited: Oct 12, 2012

    kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Don't know if this will help you but you can give it a try.

    Code:
    property theFirstName : ""
    property theLastName : ""
    tell application "Address Book"
    	repeat with thePerson in every person
    		if (the value of thePerson's email as string) contains "somedomain.com" then
    			set theFirstName to thePerson's first name
    			set theLastName to thePerson's last name
    			my displayDialog()
    		end if
    	end repeat
    end tell
    on displayDialog()
    	display dialog "first=" & theFirstName & " last=" & theLastName
    end displayDialog
     
  3. mieslep thread starter macrumors newbie

    Joined:
    Oct 12, 2012
    #3
    Not the prettiest-looking but it does the trick. New to AppleScript, a SQL query would be easier :)
     

Share This Page