Automator and/or Apple Script to copy Rich Text into email?

I have a daily task - sending a pdf file (which I create initially as a Word doc containing a table) to a distribution group. One member has asked for the contents of the pdf to be copied into the body of the email instead. I don't want to do this for everyone, only this particular person.


I'd like, when creating the document in Word, before saving it to a pdf, to highlight the table, and run a Services command or similar to copy this and paste it into an email with the recipient's address.


(If it could also fill out the Subject field of the email with the date, that would be great, but not the end of the world if not).


I've done a lot of searching to try and find a way of achieving this, using Automator and Apple Script (and also Hazel, in a more convoluted procedure) but drawn a complete blank. If anyone could help out, I'd be grateful!



MacBook Pro 14″, macOS 15.6

Posted on Aug 7, 2025 05:48 AM

Reply
12 replies

Aug 7, 2025 06:54 PM in response to EmilyLovedHim

Would the particular recipient need to copy the content of the email? If they only need to view the content, you could use the Shortcuts app to create an email that would contain pictures of the content of your PDF.


When they receive the email (at least on a Mac), the images would be automatically displayed and the recipient can choose to display the images in Small, Medium, Large or Actual Size:



Here is the shortcut you need to create:



In the last action, click Recipients and choose your particular contact. click Subject to enter the email subject. You can uncheck "Show Compose Sheet" if you want the email to be send right away. Otherwise you'll the the compose sheet of the email and you could add more informations to your email before sending it.

Aug 8, 2025 03:25 AM in response to 6x6

Thank you - that's very helpful.


The recipient does indeed only need to view the content. Having another search led me to this shortcut:


https://www.icloud.com/shortcuts/3149f8737e284e96b888c2a6f48345fc


which is *almost* what I want - but I want the copied text (a formatted table in MS Word) to keep its formatting, rather than be copied as plain text. Is that possible, do you know?

Aug 8, 2025 04:45 AM in response to EmilyLovedHim

I barely use Word so I’m no expert. But, for testing purposes (without for the moment thinking of automation), I created a table in Word, copied the table to the clipboard, created a new email and pasted the table. It looked right to me in the email.


What happens when you just repeat this procedure? Does the table appear as you wish? If so, I’m sure we could create a shortcut that automates the process.


Otherwise, if you Word/PDF document contains multiple pages and that the table is on a specific page, it is possible to use the shortcut I showed above and only extract the page (as an image) containing the table, instead of sending the whole PDF as images.

Aug 8, 2025 07:27 AM in response to EmilyLovedHim

Well, after numerous trials, Shortcuts is not going to be the solution with Services. Mac Services (at least on macOS Sequoia) do not accept Rich Text as an input (regular text is okay, though). The result is that all your table formatting is gone once it gets to the email.


I'll be investigating other options.


One solution that comes to mind if your table is not bigger than the Word window would be a shortcut that takes an interactive screenshot of the table and send its by email. Here is an example:



And ou can pin the shortcut to the Menu Bar for easy access.

Aug 9, 2025 12:02 AM in response to DancesWithWoofs

-- MICROSOFT WORD


-- ====== SETTINGS ======

property targetRecipient : "someone@example.com"

property defaultSubject : "Table from Word"

property introText : "" -- e.g., "Hi — here's the table:"; leave "" for none

-- Optional: set to "" to use your default signature

property mailSignatureName : "" -- e.g., "My Signature"

-- ======================


on run {input, parameters}

-- 1) Copy current selection from Word (rich)

try

tell application "Microsoft Word"

if not (exists document 1) then error "No Word document is open."

set sel to selection

if sel is missing value then error "Select a table (or any content) in Word first."

copy object sel -- preserves table formatting

end tell

on error errMsg

display alert "Word copy failed" message errMsg

return input

end try


-- 2) Create a new email in Mail

try

tell application "Mail"

set newMsg to make new outgoing message with properties {subject:defaultSubject, visible:true}

tell newMsg

make new to recipient at end of to recipients with properties {address:targetRecipient}

if introText is not "" then set content to introText & return & return

if mailSignatureName is not "" then

try

set message signature to signature mailSignatureName

end try

end if

end tell

activate

end tell

on error errMsg

display alert "Mail compose failed" message errMsg

return input

end try


-- 3) Paste into the message body (robust focus targeting)

tell application "System Events"

tell process "Mail"

set frontmost to true

delay 0.7


set pasted to false


-- Most layouts: window -> splitter group -> scroll area -> text area

repeat with grp in {1, 2}

try

set theArea to text area 1 of scroll area 1 of splitter group grp of window 1

set focused of theArea to true

keystroke "v" using command down

set pasted to true

exit repeat

end try

end repeat


-- Fallback path without splitter group

if pasted is false then

try

set theArea to text area 1 of scroll area 1 of window 1

set focused of theArea to true

keystroke "v" using command down

set pasted to true

end try

end if


-- Last-ditch: tab through fields, then paste

if pasted is false then

repeat 6 times

keystroke tab

delay 0.1

end repeat

keystroke "v" using command down

end if

end tell

end tell


return input

end run

Aug 9, 2025 12:15 AM in response to DancesWithWoofs

-- PAGES


-- ====== SETTINGS ======

property targetRecipient : "someone@example.com"

property defaultSubject : "Table paste"

property introText : "" -- e.g., "Hi — here's the table:"; leave "" for none

-- ======================


on run {input, parameters}

-- 1) Copy current selection from whatever app is frontmost

tell application "System Events"

set frontApp to name of first application process whose frontmost is true

if frontApp is "Mail" then

display alert "Select the table in Pages (or your editor) before running."

return input

end if

keystroke "c" using command down

end tell


-- 2) Create a new email

tell application "Mail"

set newMsg to make new outgoing message with properties {subject:defaultSubject, visible:true}

tell newMsg

make new to recipient at end of to recipients with properties {address:targetRecipient}

if introText is not "" then set content to introText & return & return

end tell

activate

end tell


-- 3) Paste into the message body (robust focus targeting)

tell application "System Events"

tell process "Mail"

set frontmost to true

delay 0.7


set pasted to false


-- Try the common hierarchy first

repeat with grp in {1, 2}

try

-- In most macOS versions: window -> splitter group -> scroll area -> text area

set theArea to text area 1 of scroll area 1 of splitter group grp of window 1

set focused of theArea to true

keystroke "v" using command down

set pasted to true

exit repeat

end try

end repeat


-- Fallback: some layouts omit the splitter group nesting

if pasted is false then

try

set theArea to text area 1 of scroll area 1 of window 1

set focused of theArea to true

keystroke "v" using command down

set pasted to true

end try

end if


-- Last-ditch: walk focus with TABs a few times, then paste

if pasted is false then

repeat 6 times

keystroke tab

delay 0.1

end repeat

keystroke "v" using command down

end if

end tell

end tell


return input

end run

Aug 9, 2025 06:10 AM in response to DancesWithWoofs

I can confirm that this Word intended AppleScript does indeed reproduce a complicated table from Word 16.99.2 into a new Mail message on macOS Sequoia v15.6. Even the table title if also selected.


The table in Word:



The table reproduction in Apple Mail, with values elevated position in cells:



The first time one runs this Automator Quick Action, several security dialogs will appear that can be resolved by clicking OK in them. The last one states that Mail cannot send key strokes and the script ends prematurely. The next time this Service is run, no security dialogs appear and the script just works.


One caveat is that using GUI scripting based on current design hierarchy of splitter groups, scroll areas, etc. in a given application can and do change at Apple's whim. This may work in Sequoia, but depending upon changes made to applications for the forthcoming Tahoe, it may break this AppleScript.


Personally, I rarely use GUI scripting for the preceding paragraph reason. Debugging application design elements is not much fun and can be time consuming horrible.

Aug 9, 2025 04:58 AM in response to EmilyLovedHim

i don't have Word on my computer, but i do have Pages. i tested this with Pages & it works perfectly.

i included the Apple Script in 2 png files to preserve the formatting. for some reason it kept removing the formatting when i pasted it into the Code Insertion here.


have fun!


--------


Setup (Quick Action)


  • Automator → New → Quick Action

  • “Workflow receives” = no input in any application
  • Add Run AppleScript, paste the corresponding script from below (Microsoft Word or Pages) 
  • edit "someone@example.com" at the top
  • Save (e.g., “PasteTable->Mail”), 
    • OPTIONAL : assign a hotkey in System Settings → Keyboard → Shortcuts → Services/Quick Actions
  • Ensure AutomatorMicrosoft Word, and Mail are allowed in Privacy & Security → Accessibility (hit the plus (+) to add each Application)
    • A popup might appear when you first set this off. you need to allow Mail & Word (or Pages) privacy access


TO RUN

  • Copy the table
  • Microsoft Word/Services/General/PasteTable->Mail 
    • Pages should be similar


1) edit the email title & recipient in the Apple Script

2) Run the Service - email will open with the table already pasted into the body of a new email. 

3) if all looks good then hit "send"


UNFORTUNATELY THE FORMATTING GETS SCREWED UP WHEN I PASTE IT INTO THE CODE INSERTION, SO HERE ARE 2 PNG FILES WITH THE APPLE SCRIPT - ONE FOR WORD & ONE FOR PAGES. JUST COPY & PASTE THE DESIRED APPLE SCRIPT INTO THE AUTOMATOR SHELL


==============WORD==============


==============PAGES==============



[Edited by Moderator]

Automator and/or Apple Script to copy Rich Text into email?

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