Skip navigation
This discussion is archived

AppleScript to change font of a new message contents in Mail

3695 Views 4 Replies Latest reply: Mar 3, 2009 4:31 PM by Barry Fass-Holmes RSS
Barry Fass-Holmes Level 6 Level 6 (11,895 points)
Currently Being Moderated
Mar 3, 2009 12:21 PM
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)
  • Camelot Level 8 Level 8 (45,670 points)
    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.
    Mac OS X (10.5.6)
  • Camelot Level 8 Level 8 (45,670 points)
    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
    Mac OS X (10.5.6)

Actions

More Like This

  • Retrieving data ...

Bookmarked By (1)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.