I have written an AppleScript that exports the Pages content to your interactive choice of Word, PDF, or RTF documents and then automagically opens a new Mail message with same document attached. It can be run with an open document in Pages, or run without Pages and it will pop a file chooser over the default Pages template chooser. You then select the Pages document, it gets exported and attached to new Mail per above.
I have tested this with Pages v12.2 on Ventura and have no reason to believe it would not work on Monterey too. It also works in a Shortcuts Run AppleScript and the Shortcuts allows you to save it to your Dock for one-click launch.
Here is the AppleScript that you can copy/paste into Dock > Launchpad > Other > Script Editor, then click the hammer icon on the Script Editor and then run the script to test it for yourself.
use scripting additions
property exportOptions : {"Word", "PDF", "RTF"}
property extDict : {msword:"docx", apdf:"pdf", rtf:"rtf"}
tell application "Pages"
activate
if not (exists front document) is true then
set pages_doc to (choose file of type {"Pages"} default location (path to desktop)) as text
set thisDoc to open pages_doc as alias
else
set thisDoc to front document
end if
set docPath to (thisDoc's file) as text
set basename to text 1 thru ((offset of "pages" in docPath) - 1) of docPath
set exportFormat to (choose from list exportOptions ¬
with title "Export Options" default items {"Word"})
if exportFormat is false then return
with timeout of 1200 seconds
if exportFormat contains "Word" then
set expDoc to basename & msword of extDict
export thisDoc to file expDoc as Microsoft Word
else if exportFormat contains "PDF" then
set expDoc to basename & apdf of extDict
export thisDoc to file expDoc as PDF with properties {image quality:Best}
else
set expDoc to basename & rtf of extDict
export thisDoc to file expDoc as formatted text
end if
end timeout
close thisDoc saving no
end tell
tell application "Pages" to if it is running then quit
-- ensure exported file extension is visible in the Finder as by default it is not
tell application "Finder"
try
if exists (item expDoc as alias) then
set extension hidden of (item expDoc as alias) to false
end if
end try
end tell
set theRecipients to {" "}
set theAttachment to (alias expDoc)
set theContent to "Test content" & return & return & "Attachment:" & return
log (theAttachment) as text
tell application "Mail"
activate
set theMessage to (make new outgoing message with properties {visible:true, subject:"File Attachment test", content:theContent & return & return})
tell theMessage to (make new to recipient with properties {address:theRecipients})
tell theMessage
tell content to make new attachment with properties {file name:theAttachment} at after the last paragraph of it
end tell
delay 2
# send theMessage
end tell
To build it as a macOS Shortcut app, you do the following:
- Dock > Other > Shortcuts
- Shortcuts > New
3. Enter run in the search field and choose Run AppleScript from the results.
4. Click in front of the on run {input, parameters} line and press return. Copy and paste the use scripting additions and two property statements before the on run {input, parameters} clause. Press return afterward to open up an empty line. Click the hammer icon. It will now look like this:
![](https://discussions.apple.com/content/attachment/3cfcf377-2556-43db-9166-87333e09161e)
5. Select the single line that says (* Your script goes here *) and leave it selected. Then copy/paste the rest of the AppleScript source from the first tell statement to the end of the script onto that selection. Click the hammer icon to compile this Shortcuts Run AppleScript. Now the finished Shortcut will look like this, since I cannot expand the shortcut window to select as I did above and perform a screen shot. See my second post in this thread that avoids the 5000 character limit that blocked posting the full Shortcut code.