简体   繁体   English

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

[英]Send email from clipboard without opening mail.app — with conditions

I asked the question Send email from clipboard without opening mail.app and got the code 我问了一个问题, 从剪贴板发送电子邮件而不打开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

now I wonder, how could I have a script that do the same thing, but modifies it like this: if the Subject is the first 10 words, and iff the clipboard har more than 10 words, then the clipboard is cut off. 现在,我想知道,我怎么有一个脚本可以做同样的事情,但是要像这样修改它: 如果主题是前10个单词,并且如果剪贴板超过10个单词,则剪贴板被切断。 For example like this "hello there baby this is a long message sent with... [see notes]" and then the enitre message (ie "hello there baby this is a long message sent with my new email, see you.") is in the content of the email. 例如,例如“您好,宝贝,这是一条长消息,并通过...发送([请参见注释]”),然后再发送enitre消息 (例如,“您好,宝贝,这是一条长消息,并通过我的新电子邮件发送,再见。”)在电子邮件的内容中。

Replace the set subject ... and set content ... lines in your script with the following: 用以下命令替换脚本中的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

Links to references: 引用链接:


@adayzdone has a good point - sometimes using words of to split a string to a list then reassembly with text item delimiters can mess up the input data. @adayzdone有一个好处-有时使用words of将字符串拆分为列表,然后使用text item delimiters进行重组可能会弄乱输入数据。 You could do this instead: 您可以改为:

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