Mail - Body Copy - Center Text?

When using AppleScript to compose a new mail message, Is it possible to centre content in the Mail application without using UI scripting? Is there a paragraph property that works?

I only see properties for color, font and size in Applescript’s library for Mail (text suite).


Is it horizontal center, vertical center or both?

Your hope seems to be very interesting but hard to realize.

If you want to control (maybe ritch content) email layout, you’d better to co-work with page layout softwares such as Adobe InDesign or Pages.

These page layout applications have layout control functions and can export content as RTF or image .

You can make new mail message with RTF.
You can make new mail message with image.

So, you can control mail layout with various ways.

Good Luck!

Model: MacBook Pro 2012
AppleScript: 2.7
Browser: Safari 12.1.2
Operating System: macOS 10.14

I think, it can be done in too. It is enough 1) to get the half length of the window in which the message is composed, then 2) calculate the half length of each paragraph, then 3) calculate how many spaces you need to add to the left of each paragraph so that the middle of the paragraph coincides with the middle of the window.

Thanks both for your proposed solutions! I will give them both a try.

It’s quite easy to center the selected item using GUI scripting.

I apologizes but you will see the french names reported by the script.

tell application "Mail" to activate

tell application "System Events" to tell process "Mail"
	set frontmost to true
	tell window "Nouveau message"
		-- class of UI elements --> {static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, button, static text, text field, scroll area, pop up button, static text, button, button, button, toolbar, group}
		tell group 1
			--class of UI elements --> {pop up button, pop up button, color well, color well, group, group, menu button, menu button}
			-- class of UI elements of group 1 --> {checkbox, checkbox, checkbox, checkbox}
			-- class of UI elements of group 2 --> {button, button, button}
			tell group 2
				-- description of buttons --> {"aligner à gauche", "centrer", "aligner à droite"}
				click button 2 -- Center the selection
			end tell
		end tell
	end tell
end tell

As you may see I disabled the instructions used to get infos about the UI elements.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 6 septembre 2019 16:13:16