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

AppleScript to change font of a new message contents in Mail

Hi,

The following script executes in Leopard.6 without returning any errors, however the contents of the new message remain set in Lucida Grande instead of Times.

Could someone please educate me on what needs to be changed in this script so that it functions properly?

Thanks in advance!

tell application "Mail"
set Out_Message to make new outgoing message
set theFont to {"Times"}
tell Out_Message
set font of content to theFont
set size of content to (14)
set visible to true
end tell
end tell

MacBook Pro (Santa Rosa), Mac OS X (10.5.6)

Posted on Mar 3, 2009 12:21 PM

Reply
4 replies

Mar 3, 2009 3:56 PM in response to Barry Fass-Holmes

Your problem is quite simply that you're trying to set the font to {"Times"}

In AppleScript parlance, {"Times"} is a list. In this case a list containing a single text item.

However, when you set the font of the message content you need to specify the name of the font to use. You can't set the font to be a list.

So your solution is simple. Change the line:

set theFont to {"Times"}


to:

set theFont to "Times"


Now you have a text object that you can pass as the font to use.

Mar 3, 2009 4:03 PM in response to Camelot

Camelot,

Thank you very much for replying. Well duh! Now I know for the future.

However...

I have modified the script as shown below.

It executes without returning any errors, but the message contents still are Lucida Grande instead of Times.

tell application "Mail"
set Out_Message to make new outgoing message
set theFont to "Times"
tell Out_Message
set font of content to theFont
set size of content to (14)
set visible to true
end tell
end tell

Mar 3, 2009 4:22 PM in response to Barry Fass-Holmes

It executes without returning any errors, but the message contents still are Lucida Grande instead of Times.


It appears that Mail.app won't set the font of the text until there's some text in the message - which kind of makes sense when you think about it - there is no content for which you can set the font...

So the simple fix seems to be to include a line that sets the message body. It shouldn't matter what you use, even a space should be valid:

tell application "Mail"
set Out_Message to make new outgoing message
set theFont to "Times"
tell Out_Message
set the content to "blah"
set font of content to theFont
set size of content to (14)
set visible to true
end tell
end tell

Mar 3, 2009 4:31 PM in response to Camelot

Hi Camelot,

Thank you again for taking time to reply again.

And, duh again! Now I know for the future.

OK, instead of "Blah" or whatever, the following inserts my selected signature and changes its font to Times.

-- Display a list of all the user's defined signatures. Skip if no signatures are defined.
tell application "Mail" to set everySignature to name of every signature
set theSignature to ""
if (count of everySignature) is greater than 0 then
set everySignature to {"None"} & everySignature
set theResult to choose from list everySignature with prompt ¬
"Select a signature to use with this message:" default items {"None"} without multiple selections allowed
if theResult is not equal to false then
tell application "Mail" to set theSignature to signature (item 1 of theResult)
end if
end if

tell application "Mail"
set Out_Message to make new outgoing message
set theFont to "Times"
tell Out_Message
set the content to item 1 of theResult
set font of content to theFont
set size of content to (14)
set visible to true
end tell
end tell

AppleScript to change font of a new message contents in Mail

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