Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript(Mail) modifies the text color if a document is attachet in dark mode

In Big Sur with the dark mode selected, if an attachment is added to a message, the text color is modified.


By running the following script, the font color of the Email is changed:

{code

"

tell application "Mail"
	set msg to make new outgoing message with properties {visible:true, subject:"this email contains a wrong body font color"}
	set content of msg to "this text color will be modified"
	tell msg to make new attachment with properties {file name:POSIX file "/Users/anyUserName/anyFile.pdf" as alias}
	activate
	msg
end tell

"

I think this is a bug. The text color should not be changed. If the email is opened in another Email client in light mode, the text is white and the user cannot see it.

It there is no attachment, there is no problem.



What do you think?

MacBook Pro 13″, macOS 11.1

Posted on Jan 28, 2021 5:01 AM

Reply

Similar questions

4 replies

Jan 28, 2021 8:41 AM in response to VikingOSX

Thank you for your quick response @VikingOSX!

Another option is to write the Mail with HTML. But I do not understand why Mail modifies the content of the message this way. I think this could be better implemented, lets say this is not a bug, it is an improvement... 😃


Anyway.


Can you tell me how can I also change the background color?

Or how can I set the Mail as plain text(instead of rich text)?


And last but not least, where can I find the documentation? I did not find any documentation about this, I just found this:

https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/introduction/ASLR_intro.html


Thank you in advance!

Jan 28, 2021 6:21 AM in response to Ciruman

Since you are working in the default HTML behind the scenes, it will default to black text, and you need to designate a color for that text, or the words of that text:


use scripting additions

tell application "Mail"
	set msg to make new outgoing message with properties {visible:true, subject:"this email contains a wrong body font color"}
	set content of msg to "this text color will be modified"
	set color of words of msg to {65535, 0, 0}  # red text
	-- tell msg to make new attachment with properties {file name:POSIX file "/Users/anyUserName/anyFile.pdf" as alias}
	activate
	msg
end tell


Jan 28, 2021 10:17 AM in response to Ciruman

When you are creating a new outgoing message in AppleScript, Mail has no clue about the current appearance mode (dark/light) and will default the text to black. That is fine when you have the appearance mode set to Light, but clearly not for Dark. Nothing you can do about that, other than color the text of the outgoing message, or do plain text.



Here is a StackOverflow link on how to use your AppleScript to tell mail to make a plain text message.


In AppleScript, when you are dealing with an application that has an AppleScript dictionary (Script Editor > Open Dictionary… > Mail), you are at the mercy of the application's AppleScript reserved words.


Although you can set the background color of an existing message, there is no means to set the background color of an outgoing message using the AppleScript dictionary for Apple Mail, without manually composing the outgoing message in HTML and using CSS for styling.

Feb 1, 2021 2:01 AM in response to VikingOSX

Thank you for the feedback and the information.


I compared the content of the Email created using applescript with Attachment and without Attachment, both in rich text. Once the attachment is added, Mail adds some HTML lines of code that define the text color. This is the reason for the problem. I still think this should not happen. If I create an Email manually, I can attach the file and Mail adds the content without adding these problematic HTML lines of code.


The solutions about changing the email format to plain text by navigating through the UI menus might be interesting for some people, but I find it fragile, if Apple changes the UI controls(move them to another location, renames the menu, etc.) the solutions do not work anymore.


But I think the robust solution would be to create the email with HTML and there define the text and background color.


Thank you very much for the information, it helped me a lot.

Applescript(Mail) modifies the text color if a document is attachet in dark mode

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.