2

I have Automator running a shell script that ends with cat "tempfile.txt". The cat command should output the contents of tempfile.txt. The file tempfile.txt contains just the following three paragraphs over five lines:

1st paragraph Lorem

2nd paragraph Lorem ipsum

3rd paragraph Ut enim

I have this chained in Automator to the "New Mail Message" action. The instructions for this action say that "If text is received from a previous action, the text is appended to the message."

The expected behavior is therefore that the body of the email message contains those three paragraphs. Instead, it contains only the third—shown here:

screenshot of generated email

Below is the relevant part of the workflow. In it we can see in the Results for the shell script that all three paragraphs are being passed to the "New Mail Action." Why does this not put all of the input text file into the message body?

enter image description here

Update (further info): If I swap in the "Create New Outlook Mail Message" action in place of the Mail.app action, all three paragraphs are successfully passed to the body of the new message in Outlook. However, they are passed without line breaks.

1

It looks like there may be a bug in New Mail Message action in Automator. If you are interested in an AppleScript workaround, where the output of the Run Shell Script action is formed into the content of the new mail message using AppleScript code to create a new mail message, here's an example workaround.

In place of the New Mail Message action use a Run AppleScript action, after the Run Shell Script action, with the following example AppleScript code:

on run {input, parameters}
    set theMessageContent to ""
    repeat with i from 1 to (count of input)
        set theMessageContent to theMessageContent & item i of input & linefeed
    end repeat
    tell application "Mail"
        activate
        set theMessage to make new outgoing message with properties {visible:true, content:theMessageContent}
    end tell
end run

This creates a new message that looks like the following example image.

If you need too, you can add additional properties, as in this example AppleScript code:

on run {input, parameters}
    set theMessageContent to ""
    repeat with i from 1 to (count of input)
        set theMessageContent to theMessageContent & item i of input & linefeed
    end repeat
    tell application "Mail"
        activate
        set theMessage to make new outgoing message with properties {visible:true, subject:"Hello World", content:theMessageContent}
        tell theMessage
            make new to recipient at end of to recipients with properties {name:"John Doe", address:"johndoe@domain.com"}
        end tell
    end tell
end run

Obviously, you'll need to change the value of the additional properties, and or add more properties then shown, to fit your needs. You can look in Mail's AppleScript Dictionary in Script Editor for additional applicable properties.

This creates a new message that looks like the following example image.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .