Applescript:使用用户输入从通讯簿获取联系人电子邮件并添加到邮件消息中

Applescript:使用用户输入从通讯簿获取联系人电子邮件并添加到邮件消息中,applescript,apple-mail,Applescript,Apple Mail,我想知道我可以使用什么脚本将联系人的电子邮件地址添加到Mac Mail 这就是我到目前为止所做的,它要求各种输入,然后使用这些输入来编译消息。消息的其余代码工作正常,但我希望脚本在Contacts中查找此人(基于输入),并将此处列出的邮件地址添加到to字段中的消息中: --User Inputs to get Client details display dialog "You are about to Create Outgoing e-mail for: Test Please enter

我想知道我可以使用什么脚本将联系人的电子邮件地址添加到Mac Mail

这就是我到目前为止所做的,它要求各种输入,然后使用这些输入来编译消息。消息的其余代码工作正常,但我希望脚本在Contacts中查找此人(基于输入),并将此处列出的邮件地址添加到to字段中的消息中:

--User Inputs to get Client details
display dialog "You are about to Create Outgoing e-mail for: Test

Please enter Client's First Name:" default answer "First Name"
set ClientName to text returned of result
display dialog "Please enter Client's Last Name:" default answer "Last Name"
set ClientLastName to text returned of result

--Create e-mail
tell application "Mail"
set theMessage to make new outgoing message with properties {visible:true, subject:"Test", content:"Hi " & ClientName & ",
"}

tell theMessage
    make new to recipient at end of to recipients with properties {address:ClientName  & ClientLastName}
end tell
end tell

这将创建消息并将“ClientName+LastName”添加到字段中,但我仍然需要进入并查找邮件地址。我希望通讯簿按姓名查找此人,然后在“收件人”字段中添加他的地址。

这很快就失控了:

repeat
    display dialog "You are about to Create Outgoing e-mail for: Test
    Please enter Client's First Name:" default answer "First Name"
    set ClientName to text returned of result
    display dialog "Please enter Client's Last Name:" default answer "Last Name"
    set ClientLastName to text returned of result
    tell application "Address Book" to set myContact to every person whose first name is ClientName and last name is ClientLastName
    if myContact ≠ {} then
        exit repeat
    else
        display dialog "There is not match for " & ClientName & space & ClientLastName & " in your Address Book." buttons {"Try again", "Cancel"} default button "Try again"
    end if
end repeat

tell application "Address Book"
    if (count of myContact) > 1 then
        repeat with aPerson in myContact
            display dialog "More than one person in your Address Book is named " & ClientName & space & ClientLastName & ". Please select your contact..." & aPerson's vcard buttons {"Select", "Next", "Cancel"} default button "Select"
            if button returned of the result = "Select" then
                set myContact to contents of aPerson
                exit repeat
            end if
        end repeat
    else if (count of myContact) = 1 then
        set myContact to first item of myContact
    end if

    repeat
        set contactEmail to emails of myContact
        if contactEmail ≠ {} then
            exit repeat
        else
            display dialog "There is not an email listed for " & ClientName & space & ClientLastName buttons {"Cancel"} default button "Cancel"
        end if
    end repeat

    if (count of contactEmail) > 1 then
        set theEmails to {}
        repeat with anEmail in contactEmail
            set end of theEmails to label of anEmail & ": " & value of anEmail
        end repeat
        set contactEmail to first item of (choose from list theEmails with prompt "Please select an email address:")
        set AppleScript's text item delimiters to ": "
        set contactEmail to text item -1 of contactEmail
        set AppleScript's text item delimiters to {""}
    else if (count of contactEmail) = 1 then
        set contactEmail to value of first item of contactEmail
    end if
end tell

tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:true, subject:"Test", content:"Hi " & ClientName & ",
"}

    tell theMessage
        make new to recipient at end of to recipients with properties {address:contactEmail}
    end tell
end tell

sjees!让我快速地看一下,试试看。。。非常感谢!非常感谢。效果很好。这节省了我很多时间