X

Script-invoked attachments in Mail resulting in black backgrounds

We were recently contacted by a reader who uncovered a problem that appeared after installing Safari 5.0 on his Mac, in which using Applescript to attach messages to an e-mail the program results in a properly appended message that has a black background for the message content.

Topher Kessler MacFixIt Editor
Topher, an avid Mac user for the past 15 years, has been a contributing author to MacFixIt since the spring of 2008. One of his passions is troubleshooting Mac problems and making the best use of Macs and Apple hardware at home and in the workplace.
Topher Kessler
2 min read

We were recently contacted by a reader who uncovered a problem that appeared after installing Safari 5.0 on his Mac, in which using Applescript to attach messages to an e-mail the program results in a properly appended message that has a black background for the message content.

Here is an example script sent to us by reader "goodwinltg":


set theAttachment to choose file
tell application "Mail"
	set theMessage to make new outgoing message with properties
                    {visible:true, subject:"My Subject", content:"My Body"}
	tell content of theMessage
		make new attachment with properties {file
                    name:theAttachment} at after last paragraph
	end tell
end tell
When a script is used to append attachments, Mail will show a black box around the message contents (click for larger view).

When run, this script will ask for a file, then create a new message with "My Body" as the main text followed by the attached file. Before installing Safari 5 the file would appear normally right after the described text, but after installing the browser the text and attachment (either rendered or in icon form) are encased in a black rectangle. You can close the rectangle, but that clears out all the text and attachments.

This problem seems to be caused by the "make new attachment" command in AppleScript, since when running the body text is at first appended to the message properly, but when the attachment is appended Mail reformats the message with the black rectangle. Unfortunately, not only used is this used by custom Applescripts but also by Automator, so workflows that attach mail messages will also show this problem.

This does appear to be a small bug, which is likely with the WebKit updates supplied with Safari 5 since both Mail and Safari use Webkit and this issue has shown up in both OS 10.5 and 10.6. We encourage people who use this feature to notify Apple by using the developer bug reporter (requires a free Apple Developer ID).

Specifically, the problem is caused by Webkit creating an HTML block in the Mail message which has the "background-color" styling property set to "rgb(0,0,0)" which is black. This may be an oversight by Apple's engineers, but unfortunately without a method to directly change the styling of HTML in Mail messages there is little that can be done to the HTML.

Until this is addressed by Apple, there is a workaround that can be used. When the script is completed and the attachment is appended to the message, go to the Format menu in Mail and choose "Make Plain Text" (also done by pressing shift-command-T). This will get rid of the HTML formatting, and leave the message with just the text and the attachments. Using this option again will re-enable Rich text in the message body and allow for colors, stylings, and other formatting options, but this time without the black background.



Questions? Comments? Have a fix? Post them below or e-mail us!
Be sure to check us out on Twitter and the CNET Mac forums.