我是Applescript的新手......
在 Apple Mail 中,您可以將電子郵件另存為文本檔案:檔案 > 另存為... > 格式化“純文本”
- 是否可以使用 applescript 自動化?
- 是否可以使用applescript將郵件(以txt“格式”)保存在剪貼板中,而不是保存為txt檔案?
非常感謝。
uj5u.com熱心網友回復:
Mail.app 不會以編程方式將所選郵件匯出到 TXT。您可以使用 GUI 腳本,但在這種情況下,GUI 腳本是不好的解決方案。以其他方式存在,此處描述。
該腳本假定郵件在 Mail.app 中被選中,并在桌面上創建文本檔案,但您可以指定其他檔案夾。.
-- Mail.app: Export Selected Message to plain text (.txt) file
-- written: by me, right now
use AppleScript version "2.5"
use scripting additions
use framework "Foundation"
set timeZone to (abbreviation of (current application's NSTimeZone's localTimeZone())) as text
-- Mail.app part (load remote content, get message properties)
tell application "Mail"
set download html attachments to true -- load remote content as well
tell (item 1 of (get selection)) -- here we tell to 1st selected message
set {theSubject, fromHider} to {subject, "From: " & sender}
tell (get date sent) -- build here "Date: ....." text line
set dateSentHider to "Date: " & date string & " - " & time string & " " & timeZone
end tell
set {toHider, messageContent} to {"To: " & address of to recipient 1, content}
end tell
end tell
set allText to fromHider & linefeed & "Subject: " & theSubject & linefeed & dateSentHider & ?
linefeed & toHider & linefeed & linefeed & messageContent
-- replace every ":" symbol in theSubject with "_"
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set {itemList, AppleScript's text item delimiters} to {text items of theSubject, "_"}
set {theSubject, AppleScript's text item delimiters} to {itemList as text, ATID}
-- build destination file's Posix path, write to it
set theFile to POSIX path of (path to desktop folder) & theSubject & ".txt"
-- or,
-- set theFile to POSIX path of (choose folder) & theSubject & ".txt"
(current application's NSString's stringWithString:allText)'s writeToFile:theFile atomically:true ?
encoding:(current application's NSUTF8StringEncoding) |error|:(missing value)
您也可以在剪貼板中保存訊息(以 txt“格式”)。簡單地:
set the clipboard to allText
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/496258.html
上一篇:Gmail電子郵件發送c#
