Using AppleScript to set a mail message to Plain Text

独自空忆成欢 提交于 2020-02-15 08:38:09

问题


I have an AppleScript that nicely collates information and creates an email message with attachments.

I cannot find a way for the script to set the message format to "Plain Text" which is required by the receiving inbox (rather than the default "Rich Text").

Is there an AppleScript way (or trick) to setting the message format to "Plain Text"?


回答1:


I found this question while trying to solve exactly this problem. Eventually I came up with the following solution:

tell application "Mail"
    set newMessage to make new outgoing message 
        with properties {visible:true,
                         subject:"message title",
                         sender:"sender@from.address",
                         content:mailBody}
    tell newMessage
        make new to recipient with properties {address:"mail@recipient.com"}
    end tell
    activate
end tell

tell application "System Events"
    click menu item "Make Plain Text" of ((process "Mail")'s (menu bar 1)'s (menu bar item "Format")'s (menu 1))
end tell

Hopefully someone will find this useful, I know I would have several hours ago!

This is tested on Mail versions 7.3 and 12.4. Newer, or older, versions might need different menu titles.




回答2:


Before the section in your script that creates a message, add this line.

 tell application "Mail" to set default message format to plain text

At the very end of the script add this to reset the value

 tell application "Mail" to set default message format to rich text



回答3:


You can use keyboard shortcut shiftt also to change the message format to plain text:

tell application "System Events" to keystroke "t" using {command down, shift down}

Tested in Mail version 12.4



来源:https://stackoverflow.com/questions/12162392/using-applescript-to-set-a-mail-message-to-plain-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!