1

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

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

--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”添加到 To 字段,但我仍然需要进入并找到邮件地址。我希望通讯簿按名字和姓氏查找此人,然后在“收件人”字段中添加他的地址。

4

1 回答 1

2

好吧,这很快就失控了:

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
于 2012-11-19T15:47:12.513 回答