0

各アドレスに特定の添付ファイルを含むいくつかのメールを送信しようとしています。すべてのアドレスには、添付ファイル用の独自のサブフォルダーがあります。「添付ファイルの部分をつかむ」が機能せず、ハンドラーが正しく設定されているかどうかわかりません。サブフォルダーをハンドラー内のメールに渡すか、そのままにしておく必要があります。これは私の最初の長いスクリプトなので、あまり厳しくしないでください ;-)

私は実用的な解決策に近づいていると思っていますが、まだ機能していません。これまでの私のスクリプトは次のとおりです。

`  with timeout of 600 seconds

-- Liste: Alle Empfänger  

tell application "Contacts"
    set emailList to {}
    set testPersons to every person of group "Test"
    repeat with thisTestPerson in testPersons
        set end of emailList to (value of email of thisTestPerson) as string
    end repeat
end tell


-- Liste fuer die Übergabe alphabetisch sortieren 

set the_list to emailList
set otid to AppleScript's text item delimiters
set AppleScript's text item delimiters to {ASCII character 10} -- always a linefeed 
set list_string to (the_list as string)
set new_string to do shell script "echo " & quoted form of list_string & " | sort -f"
set new_list to (paragraphs of new_string)
set AppleScript's text item delimiters to otid

-- Liste: Alle Subfolder 

tell application "Finder"
    set mainfolder to choose folder "select a folder"
    set folderList to {}
    set myFolders to every folder of mainfolder
    repeat with attachFolder from 1 to (count of myFolders)
        set end of folderList to attachFolder as string
    end repeat
end tell

-- Sicherheits-Check

set count1 to count of myFolders
set count2 to count of new_list
if count1 is not equal to count2 then
    display dialog "Houston, we have a problem:" & return & "Die beiden Listen sind nicht gleich lang..." buttons {"ok"} with icon 2
    return
end if
 end timeout

 --handler processfolder(myFiles)

 on processfolder(myFiles)
tell application "Mail"
    activate
    set theAddress to (item i of emailList)
    set theMex to (make new outgoing message at end of outgoing messages with   properties {visible:true, subject:"Subjectheader",   content:"email body"})

    tell content of theMex
        make new attachment with properties {file name:FileList} at after last paragraph

    end tell
    tell theMex
        make new to recipient at end of to recipients with properties {address:theAddress}

    end tell
    send theMex
end tell
end processfolder

-- grab attachments and send mail   

tell application "Finder"
repeat with myFolder from 1 to (count of folderList)
    set FileList to {}
    set myFiles to entire contents of myFolder
    repeat with thisFile in myFiles
        set end of FileList to thisFile as string
    end repeat
    my processfolder(myFiles)
end repeat
 end tell
display dialog (count1 as string) & " Nachrichten verschickt."

end`

ハンドラーは問題なく動作するはずです。サブフォルダ リストとアドレス リストの一致は依然として問題のようです。「添付ファイルを取得してメールを送信する」という繰り返しループで問題が解決するかどうかはわかりません。これは繰り返しループの扱いが難しく、私はまだ苦労しています。私がまだ間違っていることについての簡単な考えはありますか?

役に立ってくれてありがとう!本当に感謝しています!マルコ

4

2 に答える 2

1

handler でパラメータとして変数を渡す必要があります。

1- (item i of emailList): iおよびemailListがハンドラーで定義されていません。

2- {file name:FileList}: FileListがハンドラーで定義されていません。ファイル名はパスのリストではなく、タイプaliasまたはのパスである必要があります。string

set myFiles to entire contents of myFolder: myfolder変数は でintegerentire contentsフォルダーとファイルが含まれます。フォルダーにサブフォルダーが含まれていない場合は、役に立ちませ entire contentsfiles of xFolder

残りは問題ありませんが、不要な行が含まれています。

スクリプトは次のとおりです。

with timeout of 600 seconds
    -- Liste: Alle Empfänger  

    tell application "Contacts"
        set emailList to value of email 1 of every person of group "Test"
    end tell

    -- Liste fuer die Übergabe alphabetisch sortieren 

    set otid to AppleScript's text item delimiters
    set AppleScript's text item delimiters to {linefeed}
    do shell script "echo " & (quoted form of (emailList as string)) & " | sort -f"
    set emailList to (paragraphs of the result)
    set AppleScript's text item delimiters to otid


    -- Liste: Alle Subfolder 

    activate
    set mainfolder to choose folder "select a folder"
    tell application "Finder" to set folderList to folders of mainfolder


    -- Sicherheits-Check

    set count1 to count folderList
    if count1 is not equal to (count emailList) then
        display dialog "Houston, we have a problem:" & return & "Die beiden Listen sind nicht gleich lang..." buttons {"ok"} cancel button "ok" with icon 2
    end if
end timeout

-- grab attachments and send mail   

repeat with i from 1 to count1
    try
        tell application "Finder" to set myFiles to (files of entire contents of (item i of folderList)) as alias list
        my processfolder(myFiles, item i of emailList)
    end try -- no error on empty folder
end repeat
display dialog (count1 as string) & " Nachrichten verschickt."


on processfolder(tFiles, theAddress)
    tell application "Mail"
        activate
        tell (make new outgoing message at end of outgoing messages with properties {visible:true, subject:"Subjectheader", content:("email body" & linefeed & " ")})
            make new to recipient at end of to recipients with properties {address:theAddress}
            tell content to repeat with tFile in tFiles
                make new attachment with properties {file name:tFile} at after last paragraph
                make new character with data linefeed at after last paragraph
            end repeat
            send
        end tell
    end tell
end processfolder
于 2012-10-19T20:07:19.030 に答える
0

されております!あなたと他の 1 人か 2 人のプロのおかげで、私は今、automator、bash ライン、および (主に) applescript を使用した美しいバルク メール スクリプト ルーチンを手に入れました。私は仕事の応募に使用していますが、メール、MS Word、および Excel (またはアドレス帳) の特定の連絡先リストを使用して、個別に一括メールを送信したい場合に使用できます。完全にするために、必要なすべての手順を追加します。x 個の名前、電子メール アドレス、個人アドレスの任意のリストを使用して、x 個のサブフォルダーを生成できます。このサブフォルダーには、x 個の個人化された手紙と個人化されていないドキュメントが含まれています (ありがとう、Jack! ドキュメントの追加は完全に機能します)。最後のスクリプトを開始してフォルダーを選択すると、メールがすべて送信され、名前でその人に宛てられ、適切なパーソナライズされた手紙が添付されるのを見ることができます! 電子メール アドレスで異なって表示される外国人の名前のスペルを修正します。これは、"@" の前に姓を使用する電子メール アドレスに最適であり、名が姓の前に設定されている場合は名を無視できるようになりました (つまり、firstname.lastname@company.com)。皆様、ご協力ありがとうございました!これは素晴らしいチームの努力でした。家に帰ったらすぐに投稿します。ここと他の関連する質問に投稿する必要がありますか、それとも共有フォーラムがありますか?

于 2012-10-24T06:53:47.953 に答える