I have followed your steps and created the shortcut. It all looks the same as yours. But I get the following error message..
Numbers got an error: The document “Updates (All Markets)” could not be exported as “missing value”.
I am unsure what the missing value is or could be. The following is the script of the shortcut. This too is my first attempt at creating a "runscript shortcut". I have gone through the steps many times and it keeps giving me the same error. I appreciate any tips. I am running Ventura 13.0.1 with number version 12.2.1 (7035.0.161)
use scripting additions
property exportOptions : {"PDF", "Excel", "CSV"}
property extDict : {apdf:".pdf", msexcel:".xlsx", acsv:".csv"}
on run {input, parameters}
tell application "Numbers"
activate
if not (exists front document) is true then
set nbr_doc to (choose file of type {"Numbers"} default location (path to desktop)) as text
set thisDoc to open nbr_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 ".numbers" in docPath) - 1) of docPath
-- you can press return instead of clicking the OK button
set exportFormat to (choose from list exportOptions ¬
with title "Spreadsheet Export Options" default items {"Excel"})
if exportFormat is false then return
-- export chosen document format
with timeout of 1200 seconds
if exportFormat contains "Excel" then
set expDoc to basename & msexcel of extDict
export thisDoc to file expDoc as Microsoft Excel
else if exportFormat contains "CSV" then
set expDoc to basename & acsv of extDict
export thisDoc to file expDoc as CSV
else
set expDoc to basename & apdf of extDict
export thisDoc to file expDoc as PDF with properties {image quality:Best}
end if
end timeout
tell application "Numbers" 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
end tell
set theRecipeients 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 1
# send theMessage
end tell
return input
end run