2013-12-22 50 views
1

我問的問題Send email from clipboard without opening mail.app,並得到了代碼從剪貼板發送電子郵件,而無需打開mail.app - 與條件

set a to "[email protected]" 
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 

現在我不知道,我怎麼能有一個腳本,做同樣的事情,但修改它是這樣的:如果Subject是前10個單詞,並且如果剪貼板中的單詞超過10個單詞,則剪貼板被切斷。例如,像這樣的「你好,寶貝,這是一個長的消息發送... [見注]」,然後enitre消息(即「你好寶貝,這是一個很長的消息與我的新電子郵件發送,看到你。「)在電子郵件的內容中。

回答

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 
+0

你不需要使用文本項目分隔符。 – adayzdone

+0

@adayzdone - 爲什麼不呢?如果我將'(文字爲)'作爲文本'而沒有將分隔符設置爲'「,那麼這些詞將被連接起來,而沒有任何間隔。 –

+0

我讀得太快了。雖然我明白你爲什麼使用tid,但你的腳本會遇到諸如「請將一些$$$連接到1-212-555-3333」這個主題的問題。 – adayzdone

相關問題