![](/img/trans.png)
[英]Opening Mail.app From An External Application With An Attachment and Subject
[英]Send email from clipboard without opening mail.app — with conditions
我问了一个问题, 从剪贴板发送电子邮件而不打开mail.app并得到了代码
set a to "myemail@mail.com"
tell application "Mail"
tell (make new outgoing message)
set subject to (the clipboard)
set content to "content"
make new to recipient at end of to recipients with properties {address:a}
send
end tell
end tell
现在,我想知道,我怎么有一个脚本可以做同样的事情,但是要像这样修改它: 如果主题是前10个单词,并且如果剪贴板超过10个单词,则剪贴板被切断。 例如,例如“您好,宝贝,这是一条长消息,并通过...发送([请参见注释]”),然后再发送enitre消息 (例如,“您好,宝贝,这是一条长消息,并通过我的新电子邮件发送,再见。”)在电子邮件的内容中。
用以下命令替换脚本中的set subject ...
和set content ...
行:
if (count of words of (the clipboard)) is greater than 10 then set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set subject to ((words 1 through 10 of (the clipboard)) & "... [see notes]") as text set AppleScript's text item delimiters to oldDelims set content to (the clipboard) else set subject to (the clipboard) set content to "content" end if
引用链接:
count of
给出列表中元素的数量 words of
将文本字符串拆分为一个列表,每个元素代表一个单词 AppleScript's text item delimiters
来帮助拆分和联接具有不同分隔符的列表 through
关键字可以用于从列表中获取项目的子范围 @adayzdone有一个好处-有时使用words of
将字符串拆分为列表,然后使用text item delimiters
进行重组可能会弄乱输入数据。 您可以改为:
set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set cblist to text items of (the clipboard) set AppleScript's text item delimiters to oldDelims if (count of cblist) is greater than 10 then set oldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to " " set subject to ((items 1 through 10 of cblist) & "... [see notes]") as text set AppleScript's text item delimiters to oldDelims set content to (the clipboard) else set subject to (the clipboard) set content to "content" end if
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.