繁体   English   中英

从剪贴板发送电子邮件而无需打开mail.app-有条件

[英]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

引用链接:


@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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM