Applescript 我可以将子文件夹中的多个附件添加到邮件中吗?

Applescript 我可以将子文件夹中的多个附件添加到邮件中吗?,applescript,email-attachments,apple-mail,Applescript,Email Attachments,Apple Mail,尝试为每个地址发送多封带有特定附件的邮件。每个地址都有自己的附件子文件夹。“抓取附件部分”不起作用,我不确定处理程序是否设置正确:我应该将子文件夹传递给处理程序中的mail,还是保持原样。这是我的第一个长篇剧本,所以请不要太苛刻;-) 我在想,我离工作解决方案越来越近了,但我仍然无法让它发挥作用。以下是我目前的脚本: ` with timeout of 600 seconds -- Liste: Alle Empfänger tell application "Contacts"

尝试为每个地址发送多封带有特定附件的邮件。每个地址都有自己的附件子文件夹。“抓取附件部分”不起作用,我不确定处理程序是否设置正确:我应该将子文件夹传递给处理程序中的mail,还是保持原样。这是我的第一个长篇剧本,所以请不要太苛刻;-)

我在想,我离工作解决方案越来越近了,但我仍然无法让它发挥作用。以下是我目前的脚本:

`  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`
我相信处理程序应该可以正常工作。将子文件夹列表与地址列表匹配似乎仍然是个问题,我不确定我的重复循环“抓取附件并发送邮件”是否奏效。重复循环的使用是一个棘手的问题,我仍在努力解决这个问题。对我仍然做错的事情有什么快速的想法吗

谢谢你的帮助!我真的很感激!
marco

必须将变量作为参数传递到处理程序中:

1-
(emailList的项目i)
iemailList未在处理程序中定义

2-
{file name:FileList}
文件列表未在处理程序中定义,文件名必须是类型为
别名
字符串
的路径,而不是路径列表

将myFiles设置为myFolder的全部内容
:变量是一个
整数
全部内容
将包含文件夹和文件,如果文件夹不包含子文件夹,
全部内容
无效,请使用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

完成了!多亏了你和一两位其他的专业人士,我现在有了一个使用automator、bash行和(主要是)applescript的漂亮的批量邮件脚本例程。我在求职申请中使用它,但你可以在任何情况下使用它,在任何情况下,你都可以通过邮件、MS Word和Excel中的任何给定联系人列表(或通讯簿)发送个性化的批量电子邮件。为了完整起见,我将添加所有必要的步骤。使用任意给定的x个姓名、电子邮件地址、个人地址列表,您可以生成x个子文件夹,其中包含x封个性化信件,而不是个性化文档(谢谢,杰克!添加文档非常有效)。一旦启动最后一个脚本并选择文件夹,您就可以看到邮件将它们全部发送出去,按姓名对此人进行寻址并附上正确的个性化信函!它纠正了在电子邮件地址中呈现不同的外来名称拼写。它最适用于在“@”之前使用姓氏的电子邮件地址,如果在姓氏(即firstname)前面设置,则现在可以忽略姓氏。lastname@company.com). 非常感谢大家的帮助!这是伟大的团队努力。
我一到家就发,我是应该在这里和其他相关问题中发,还是有一个分享论坛?

Jack,刚刚工作得很好!我会尽力去理解我做错了什么。非常感谢你的帮助!如果你有任何关于如何更好地理解不同类之间的联系以及如何处理文件和文件夹的好资料,你能告诉我吗?我已经浏览了好几个星期了,大多数初学者的脚本都专注于处理简单的数字和文本,但没有说明如何解释处理真实世界情况的上下文。再次感谢!!!!Source
Applescript常见问题解答
,转到页面底部(10个链接,每个链接包含多个主题)。如果你是编程新手,我建议你买一本关于AppleScript()的书。一般来说,我们从自己的错误中吸取教训​​在我们的第一个脚本中。所以,你写的脚本越多,你学到的就越多。耐心点。