苹果邮件应用程序,添加多个附件
问题描述:
我想在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"
\t set folderPath to folder ((get (path to home folder) as Unicode text) & "Documents:folder" as Unicode text)
\t set thefList to ""
\t set fcount to 1
\t repeat
\t \t try
\t \t \t set theFile to ((file fcount) in folderPath as alias)
\t \t \t set theFile to name of theFile
\t \t \t if thefList is "" then
\t \t \t \t set thefList to theFile
\t \t \t else
\t \t \t \t set thefList to thefList & "
" & theFile
\t \t \t end if
\t \t \t set fcount to (fcount + 1)
\t \t on error
\t \t \t set fcount to (fcount - 1)
\t \t \t exit repeat
\t \t end try
\t end repeat
\t
\t --return thefList
\t set theAttachment to theFile
end tell
repeat (fcount - 1) times
\t set rSpace to "
" & rSpace
end repeat
tell application "Mail"
\t activate
\t set theMessage to make new outgoing message with properties {visible:true, sender:"[email protected]", subject:theSubject, content:rSpace}
\t
\t
\t tell theMessage
\t \t make new to recipient with properties {address:"[email protected]"}
\t \t set acount to 1
\t \t repeat fcount times
\t \t \t
\t \t \t try
\t \t \t \t make new attachment with properties {file name:(paragraph acount of thefList)} at after the last word of the paragraph acount
\t \t \t \t set message_attachment to 0
\t \t \t on error errmess -- oops
\t \t \t \t log errmess -- log the error
\t \t \t \t set message_attachment to 1
\t \t \t end try
\t \t \t log "message_attachment = " & acount
\t \t \t set acount to (acount + 1)
\t \t end repeat
\t \t
\t \t send
\t end tell
end tell
它不添加附件,但它发送电子邮件。
如何纠正程序添加附件?
答
有一种普遍的误解:
消息的附件必须是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
线)
tell application "Mail"
activate
set theMessage to make new outgoing message with properties {visible:true, sender:"[email protected]", subject:theSubject, content:rSpace}
tell theMessage
make new to recipient with properties {address:"[email protected]"}
set acount to 1
repeat with anAttachment in attachmentList
make new attachment with properties {file name:anAttachment} at after the last word of the paragraph acount
log "message_attachment = " & acount
set acount to (acount + 1)
end repeat
-- send
end tell
end tell
非常感谢你Vadian! –