我正在尝试将多个附件添加到AppleScript中的电子邮件中。 我将主题设置为顶部的文件夹和周数。
set {b, c} to {"1/1/1000", 364876}
set {year:yy, month:mm, day:dd} to (current date)
set yy to text 3 thru 4 of (yy as text)
set d to ((((current date) - (date b)) div days + c) div 7) + 1
set e to ((((date ("1/1/" & (year of the (current date)) as string)) - (date b)) div days + c) div 7) + 1
set weekCode to (yy & (d - e) as text)
set rSpace to "
"
set theSubject to "folder Week " & (text 3 thru 4 of weekCode)
tell application "Finder"
set folderPath to folder ((get (path to home folder) as Unicode text) & "Documents:folder" as Unicode text)
set thefList to ""
set fcount to 1
repeat
try
set theFile to ((file fcount) in folderPath as alias)
set theFile to name of theFile
if thefList is "" then
set thefList to theFile
else
set thefList to thefList & "
" & theFile
end if
set fcount to (fcount + 1)
on error
set fcount to (fcount - 1)
exit repeat
end try
end repeat
--return thefList
set theAttachment to theFile
end tell
repeat (fcount - 1) times
set rSpace to "
" & rSpace
end repeat
tell application "Mail"
activate
set theMessage to make new outgoing message with properties {visible:true, sender:"my@email.com", subject:theSubject, content:rSpace}
tell theMessage
make new to recipient with properties {address:"their@email.com"}
set acount to 1
repeat fcount times
try
make new attachment with properties {file name:(paragraph acount of thefList)} at after the last word of the paragraph acount
set message_attachment to 0
on error errmess -- oops
log errmess -- log the error
set message_attachment to 1
end try
log "message_attachment = " & acount
set acount to (acount + 1)
end repeat
send
end tell
end tell
它不是添加附件,而是发送电子邮件。
如何更正程序以添加附件?
答案 0 :(得分:0)
存在一般性的误解:
邮件附件必须是=mySplitString(A2, ",")
=mySplitString(A3)
对文件的引用,而不是字符串文件名。
获取文件并在消息中创建新行的代码可以简化为
alias
并且创建消息的代码也可以缩减为(我已注释掉set documentsFolder to path to documents folder
tell application "Finder"
set folderPath to folder "folder" of documentsFolder
set attachmentList to files of folderPath as alias list
end tell
set rSpace to ""
repeat (count attachmentList) - 1 times
set rSpace to rSpace & return
end repeat
行)
send