创建Applescript以通过电子邮件发送文件
问题描述:
我想让Apple邮件应用程序接受并从我发送邮件,然后通过电子邮件将文件发送给我。例如,我想发送一封包含主题为“#FILE myfile.doc”的电子邮件,并通过主题中的#FILE标签触发脚本,然后通过电子邮件将名为“myfile.doc”的文件发回给我。创建Applescript以通过电子邮件发送文件
这些文件将始终位于相同的路径中,但能够在脚本中指定路径会很好,因此我可以为不同的目录创建不同的路径。
我对Applescript一无所知,并且涉猎Automator。我只在Mail中看到,您可以从规则中触发Applescript。所以我不知道这是否可以在Automator中完成。
请回答基本问题,因为我是这个新手。
目的是当我不在的时候从我的电脑里取出文件。
感谢, ROY
答
您可以使用邮件的邮件规则去做。将您的电子邮件地址指定为发件人,并以#FILE
开头的主题。让邮件规则触发脚本是这样的:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
tell application "Mail"
repeat with thisMessage in theMessages
set theSender to sender of thisMessage
set theSubject to subject of thisMessage
if theSubject begins with "#FILE " then
set theAnswer to make new outgoing message with properties {visible:true}
tell theAnswer
try
tell current application
set theFilePathToSend to (POSIX file (text 7 thru -1 of theSubject)) as alias
end tell
set content to "And here is your file: " & rich text 7 thru -1 of theSubject & return & return
tell content to make new attachment with properties {file name:theFilePathToSend} at after the last paragraph
on error errStr
set content to "An error occured: " & return & errStr
end try
set subject to "Re: " & theSubject
make new to recipient at end of to recipients with properties {address:theSender}
send
end tell
end if
end repeat
end tell
end perform mail action with messages
end using terms from
使用reply
-handler没有工作,但make new outgoing message
没有!指定文件的完整路径作为主题。
请注意,这是一个安全漏洞!发件人的电子邮件地址可能是伪造的,并且有人知道这可能会获得他(或她)想要的几乎每个文件。您可以在此脚本中指定允许的文件夹,即if theSubject begins with "#FILE /Users/rbarr/Desktop/Available files/" then
或只需调整邮件规则触发的条件即可。
享受,迈克尔/汉堡