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

これによりメッセージが作成され、Toフィールドに「ClientName + LastName」が追加されますが、それでもメールアドレスを検索する必要があります。名簿に名前と名前で人を検索してから、[宛先]フィールドにその人の住所を追加してもらいたいのですが。

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 に答える