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

时间:2013-12-22 19:56:29

标签: macos applescript

我问了问题Send email from clipboard without opening 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消息(即“你好宝贝这个是用我的新电子邮件发送的长消息,见到你。“)在电子邮件的内容中。

1 个答案:

答案 0 :(得分:2)

使用以下内容替换脚本中的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