AnsweredAssumed Answered

Using AppleScript Calculated and IF Statements

Question asked by ericdano on Jun 7, 2010
Latest reply on Jun 7, 2010 by FentonJones

Title

Using AppleScript Calculated and IF Statements

Post

This is driving me crazy. I want to be able to add contacts to my address book, and am trying to code in some logic to deal with if they have up to 5 email or phone numbers using IF statements.....but FileMaker keeps throwing errors. Here is the code as a Custom Function:

 

"

tell application \"Address Book\"¶

        set thePerson to make new person with properties {first name:\"" & firstName & "\", last name:\"" & lastname & "\"}¶

        make new related name at end of related names of thePerson with properties {label:\"Parents\", value:\"" & parents & "\"}¶

        make new email at end of emails of thePerson with properties  {label:\"" & emailaddress1label & "\", value:\"" & emailaddress1 & "\"}¶

        if (\""  & emailaddress2 & "\") is not null then¶

          make new email at end of emails of thePerson with properties  {label:\"" & emailaddress2label & "\", value:\"" & emailaddress2 & "\"}¶

        end if¶

        if (\""  & emailaddress3 & "\") is not null then¶

          make new email at end of emails of thePerson with properties  {label:\"" & emailaddress3label & "\", value:\"" & emailaddress3 & "\"}¶

        end if ¶ 

        if (\""  & emailaddress4 & "\") is not null then¶

          make new email at end of emails of thePerson with properties  {label:\"" & emailaddress4label & "\", value:\"" & emailaddress4 & "\"}¶

        end if¶

        if (\""  & emailaddress5 & "\") is not null then¶

        make new email at end of emails of thePerson with properties  {label:\"" & emailaddress5label & "\", value:\"" & emailaddress5 & "\"}¶

        end if¶

 

        make new phone at end of phones of thePerson with properties {label:\"" & phone1label & "\", value:\"" & phone1 & "\"}¶

        if (\""  & phone2 & "\") is not null then¶

        make new phone at end of phones of thePerson with properties {label:\"" & phone2label & "\", value:\"" & phone2 & "\"}¶

        end if¶

        if (\""  & phone3 & "\") is not null then¶

        make new phone at end of phones of thePerson with properties {label:\"" & phone3label & "\", value:\"" & phone3 & "\"}¶

        end if¶

        if (\""  & phone4 & "\") is not null then¶

        make new phone at end of phones of thePerson with properties {label:\"" & phone4label & "\", value:\"" & phone4 & "\"}¶

        end if¶

        if (\""  & phone5 & "\") is not null then¶

        make new phone at end of phones of thePerson with properties {label:\"" & phone5label & "\", value:\"" & phone5 & "\"}¶

        end if¶

        make new address at end of addresses of thePerson with properties {label:\"Home\", street:\"" & address1 & "\", city:\"" & city1 & "\", state:\"" & state1 & "\", zip:\"" & zip1 & "\"}¶

        if (\""  & address2 & "\") is not null then¶

          make new address at end of addresses of thePerson with properties {label:\"Other\", street:\"" & address2 & "\", city:\"" & city2 & "\", state:\"" & state2 & "\", zip:\"" & zip2 & "\"}¶

        end if¶

        save¶

end tell¶

-- open the new entry in the address book¶

tell application \"Finder\"¶

set theURL to \"addressbook://\" & id of thePerson¶

open location ( theURL )¶

end tell¶

"

 

Ideas? Thanks!

Outcomes