as we used this script for about 10 years now I do nothing differently compared to before when it worked. the email is selected (as we always did) and it gives this error.
set selectedMsg to (current messages)
set msgAttachment to attachments of selectedMsg
--The above too works
set attachmentName to name of msgAttachment -- → error
-- → error "Can’t get name of {}." number -1728 from name of {}
I am not an expert, but I assume as many of you have already stated, it is not possible to select messages in Outlook Mac (365) in the current version due to sandbox restrictions. So every script will fail at the moment. If anybody knows a workaround or has a solution, please let us know.
This fails:
tell application "Microsoft Outlook"
set selectedMessages to selected objects -- this fails
return selectedMessages
end tell
This fails:
tell application "Microsoft Outlook"
set selectedMessages to selection -- this fails
return selectedMessages
end tell
And this fails:
tell application "Microsoft Outlook"
set selectedMessages to current messages -- this fails
return selectedMessages
end tell
I think selecting messages would be the base of fixing many many outlook-scripts here in the forum currently, but sadly no luck yet on my system. With your script I get this error message: “error “Can’t make missing value into type record.” number -1700 from missing value to record”. The missing value seems to be the sandbox problem.
Hi,
I did not use outlook at home, (at work use windows, and allowed to install on home (corporate licensing ) installed it to try pdf output functionality.
How very strange, it all worked when I posted on 21/05 about “path to file” in another post
but did not on 22/05 !
Drag to right area of window the action Get Selected Outlook Items
Drag to right area of window the action Run AppleScript. Left it as is.
Go to “File” menu and save service as “Get Selected Outlook Items”.
Now try following. Returns it selected Outlook items or not? :
set thePath to "" & (path to library folder from user domain) & "Services:Get Selected Outlook Items.workflow"
do shell script "/usr/bin/automator '" & POSIX path of thePath & "'"
@KniazidisR - Sadly this action “Get Selected Outlook Items” seems not available and missing in Automator on my system with the newest Outlook for Mac (Version 16.49). Only “Get Selected Mail Items” is available.
This means that the new Outlook is an inferior product, a surrogate. It is written for the Mac with no AppleScript support or service support. I just don’t buy it. Sorry you already spent on a bad product.
Actually, I like Apple’s Mail.app better. So far, it suffers from a lack of automation for exporting messages as PDF
Therefore, before better times came, I wrote a script for myself here using the minimal GUI code (important for the longevity of the solution). 3 clicks only. Select message, run this:
-- Mail.app part (load remote content, open message, get its subject)
tell application "Mail"
activate
set download html attachments to true -- load remote content as well
set aMessage to item 1 of (get selection)
set theSubject to subject of aMessage
open aMessage
end tell
-- replace every ":" symbol in theSubject with "_"
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set {itemList, AppleScript's text item delimiters} to {text items of theSubject, "_"}
set {theSubject, AppleScript's text item delimiters} to {itemList as text, ATID}
-- build destination file's HFS path
set theFile to (((path to desktop folder) as text) & theSubject & ".pdf")
-- GUI scripting part (3 clicks)
tell application "System Events" to tell application process "Mail"
click menu item "Print…" of menu 1 of menu bar item "File" of menu bar 1
repeat until menu button "PDF" of sheet 1 of window 1 exists
delay 0.2
end repeat
click menu button "PDF" of sheet 1 of window 1
click menu item "Open in Preview" of menu 1 of menu button "PDF" of sheet 1 of window 1
end tell
-- Preview.app part (save as pdf)
tell application "Preview"
repeat until document 1 exists
delay 0.2
end repeat
save document 1 in file theFile
quit
end tell
-- Mail.app part (close message's window)
tell application "Mail" to close window 1
Here is version without using Preview.app. But its GUI part contains 5 operations: 3 clicks, 1 setting textfield value, and 1 keystroke:
-- Mail.app part (load remote content, open message, get its subject)
tell application "Mail"
activate
set download html attachments to true -- load remote content as well
set aMessage to item 1 of (get selection)
set theSubject to subject of aMessage
open aMessage
end tell
-- replace every ":" symbol in theSubject with "_"
set {ATID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
set {itemList, AppleScript's text item delimiters} to {text items of theSubject, "_"}
set {theSubject, AppleScript's text item delimiters} to {itemList as text, ATID}
-- build destination file's Posix path
set theFile to ((POSIX path of (path to desktop folder) as text) & theSubject & ".pdf")
-- GUI scripting part (3 clicks, 1 textfield value setting, 1 keystroke)
tell application "System Events" to tell application process "Mail"
click menu item "Export as PDF…" of menu 1 of menu bar item "File" of menu bar 1
repeat until text field 1 of sheet 1 of window 1 exists
delay 0.2
end repeat
keystroke "g" using {shift down, command down}
repeat until combo box 1 of sheet 1 of sheet 1 of window 1 exists
delay 0.2
end repeat
set value of combo box 1 of sheet 1 of sheet 1 of window 1 to theFile
click UI element "Go" of sheet 1 of sheet 1 of window 1
repeat while combo box 1 of sheet 1 of sheet 1 of window 1 exists
delay 0.2
end repeat
repeat until sheet 1 of window 1 exists
delay 0.2
end repeat
click UI element "Save" of sheet 1 of window 1
end tell
-- Mail.app part (close message's window)
tell application "Mail" to close windows