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.
As long as you will not find what fails at this level trying to execute other instruction is just wasting time.
I have some difficulty to understand why the code
tell application "Microsoft Outlook" to activate
delay 0.5
tell application "Microsoft Outlook"
set selectedMsg to (current messages)
end tell
return an empty list on your machine when it return a list of messages on other users machines.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 20 juillet 2020 16:15:48
I have no idea either Yvan.
Hi AppleScript breaks with Office 16.39. Delete all Office Apps, empty trash and install the 16.38 version.
Due to sandbox restrictions I think desktop is not a valid path to store. Try the downloads folder.
Armin
Thanks for your reply.
I am still on 16.38 so that could not be it. will try the tip with not using the desktop, maybe that is it.
and do not forget my script gets stuck much earlier at: set selectedMsg to item 1 of result
so DT would not be it and after testing is not it.
In fact your script fails before.
The instruction which fails is :
set selectedMsg to (current messages)
which is supposed to return a list of messages but return an empty list.
Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 27 juillet 2020 18:00:36
Hi Yvan
getting error
after log point 1
with item 1 highlighted
error “Can’t get item 1 of {}.” number -1728 from item 1 of {}
I have selected the messages in outlook, run the script from scripteditors’ menu
Further testing
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
Only thing to do is to upvote here: https://outlook.uservoice.com/forums/924856-the-new-outlook-for-mac/suggestions/39253423-support-applescript
My license for Microsoft Outlook is expired. Can someone test, what returns following code when the messages is selected manually?
tell application "Microsoft Outlook" to (get selection as record)
Thanks for the fresh idea KniazidisR!
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 !
I did mange to a perfect pdf from email for once
At least Get Selected Outlook Items action of Automator works or not? If it works, I can show how to resolve the problem. Try this:
- Open Automator.
- Choose [b]“Create Quick Action” /b
- 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.
You are absolutely right there, no argument here
never the less many of us stuck with it for work reasons.
Apple Script support is a requested feature for Outlook For Mac here: https://outlook.uservoice.com/forums/924856-the-new-outlook-for-mac/suggestions/39253423-support-applescript It is possible that they will bring Apple Script back, but who knows, they don’t seem in a rush and it’s Microsoft.
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
The current version of MSO (16.49) still has AppleScript support. JavaScript and Objective-C have been added. In contrast, the Automator Actions have been removed since Office 2016. The old ones (from previous installations) still ran as long as it is a 32-bit system.
I can not say how it works, because I do not use Outlook.
Yes, I already rated 1 out of 5 there answers from people at Microsoft. For lack of zero.