简体   繁体   English

将换行符添加到AppleScript中生成的Mail.app消息的电子邮件正文内容中

[英]Adding Line Break to Email Body Content of Mail.app Message Generated in AppleScript

I'm currently using the below script to send out an email with a specified subject, attachment, and body message: 我目前正在使用以下脚本发送带有指定主题,附件和正文消息的电子邮件:

on run argv
    set theSubject to (item 1 of argv)
    set theAttachmentFile to (item 2 of argv)
    set theContent to (item 3 of argv)

    tell application "Mail"

        set theAddress to {"test@gmail.com"} -- the receiver 
        set theSignatureName to "Test" -- the signature name    

        set msg to make new outgoing message with properties {subject:theSubject, content:theContent, visible:true}

        tell msg
            repeat with i from 1 to count theAddress
                make new to recipient at end of every to recipient with properties {address:item i of theAddress}
            end repeat
        end tell
        tell msg to make new attachment with properties {file name:theAttachmentFile as alias}

        set message signature of msg to signature theSignatureName

        send msg
    end tell
end run

I have been executing the script in the Mac Terminal using: 我一直在Mac Terminal中使用以下命令执行脚本:

osascript /Users/dwm8/Desktop/email.scpt "Test" "dwm8:test.pdf" "Test Message Here"

However, I would like to make a small change in regards to the body message of the email I send out. 但是,我想对我发送的电子邮件的正文消息进行一些小的更改。 Instead of sending out the message 而不是发送消息

Test Message Here

I would like the body of the email to say 我想在邮件正文中说

Test Message Here

where I am able to specify where I want a line break. 我可以在哪里指定换行符的位置。 Does anyone know how I can implement this into my existing script? 有谁知道我可以在现有脚本中实现它吗? Thanks for the help! 谢谢您的帮助!

Add a carriage return: 添加回车符:

osascript /Users/dwm8/Desktop/email.scpt "Test" "dwm8:test.pdf" "Test ^MMessage^M Here"

where ^M is what you get when you hit ctrl-v then ctrl-m. 其中^ M是按ctrl-v然后按ctrl-m时得到的结果。

You can insert carriage returns by using \\n or & return : 您可以使用\\n& return插入回车& return

"Test\nMessage\nHere"

or... 要么...

"Test" & return & "Message" & return & "Here"

The content of your message is always the 3rd argument. 消息的内容始终是第三个参数。 This argument should not be the content, but you should have as many arguments as number of lines you want. 此参数不应该是内容,但是您应该具有与所需行数一样多的参数。

In example below, the call is done with 3 lines -> 3 arguments 在下面的示例中,调用使用3行-> 3个参数完成

osascript /Users/dwm8/Desktop/email.scpt "Test" "dwm8:test.pdf" "This is content of 1st line" "content of 2nd line" "test for the content of 3rd line"

Below the beginning of the script which can read as many arguments as you want : 在脚本开头的下方,该脚本可以读取所需的任意多个参数:

set theSubject to (item 1 of argv)
set theAttachmentFile to (item 2 of argv)
set theContent to ""
repeat with I from 3 to (count of argv)
    set theContent to theContent & (item I of argv) & return
end repeat

Then add, at then end, the remaining part of your script from the tell application "mail" line. 然后,在Tell应用程序的“ mail”行中添加脚本的其余部分。 doing so, you can decide how to split line in the message content, at the call of the oascript function. 这样,您可以在调用oascript函数时决定如何在消息内容中分割行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM