Outlook 365 Mac, ‘nuking’ messages no longer working with AppleScript

In outlook 2011 I had an apple script, that would nuke messages, means permanently delete them from any folder in outlook.

I also had a keyboard shortcut assigned to it and so it made dumping spam and other uninteresting stuff really easy without putting them first in the trash and next remove them from the trash.

The script no longer works in 365 (mac version), so I am looking for a new solution. Does anybody have one?

FYI here is the script I have:

tell application "Microsoft Outlook"
         set theMsgs to the current messages -- selected messages
                  repeat with theMsg in theMsgs
                           permanently delete theMsg
                  end repeat
         on error errMsg number errNum
                  set theSubject to subject of theMsg
                  set theFolder to name of «class stor» of theMsg
                  display dialog errMsg & return & return & errNum & return & return & "(Erroring on message: " & theSubject & " in " & theFolder & ")" with icon 2
         end try
end tell

Tanks for your help

is there anybody out there with an idea?

According to the keyboard shortcuts for documentation from Microsoft for the 365 version of Outlook on the Mac, you should just be able to use Shift+Delete to permanently delete selected messages.

Should it really mean delete rather than backspace, and if you have no delete key on your keyboard (e.g. a Mac laptop’s inbuilt keyboard), then fn+Backspace should be the equivalent of pressing delete.

Hope that helps.

Thanks for posting, it is appreciated.
This is correct, however it is a two key operation. Hence the script.

Sorry, I don’t follow. I assume I’m missing something in your requirements as the key press should trigger the same functional effect as described by the AppleScript.

You had a keyboard shortcut assigned to your script, which presumably required you to press at least two keys at the same time, which is the same here. I’m also not seeing any efficiency improvement over pressing two (or more) keys simultaneously rather just one key if you had in fact tied the script to a single keypress.

If it were just a case of wanting to trigger it as part of a longer script, then AppleScript supports keypress events, so you could send that keypress to the app.

Could you explain your reasoning a bit more? I, or someone else, can probably suggest something if we can understand that limitation you’re trying to address that the built in function does not.

Thanks sylumer
No, my original script worked by only using one KB command once and unceremoniously deleted the mail forever. And yes you had to press two keys at the same time. But that was it.

Using your method it opens a dialog where I need to click OK.

I only use Outlook at work, not on the Mac, so I can’t check, but have a look in the application preferences for the Mac app equivalent of this to control that behaviour.

No such option on the Mac that I can find.

Any chance you have Keyboard Maestro?

No I do not have this, sorry.

Okay, I’ve downloaded the app, but cannot access its settings without subscribing too O365. I can however see the AppleScript dictionary. All of the elements seem to be supported, so I would suggest using Script Debugger to see if you can get any insight into what is failing when it is run.

In having a look around, I noted this query on the Microsoft community forums, and what I guess is the follow-up on Microsoft’s GitHub Support community. My experience of dealing with Microsoft in the past is that the often treat bugs and issues poorly. I’ve been asked to suggest bug fixes as enhancement suggestions on public forums in the past! But if you haven’t got anything back from there, there’s a reasonable chance it may not be positive news any way. Microsoft support are good at pointing you to KBA, but are not going to help you outside of that - as you can probably tell from “AppleScript” for their own app not even being classed as in scope.

If you can’t get a lead on the issue with Script Debugger, don’t have Keyboard Maestro (or equivalent), and don’t have the same confirmation disable option available as in Windows, then I think you’ll be stuck for a reliable option. Which of course could reasonably lead to what I would term an unreliable option.

For me an unreliable option (so please do not take this as a recommendation) would be to create an AppleScript that sends Shift+Delete to Outlook, pauses for say 1 second, and then sends return. That should, I think (again I can’t test this), then trigger the default button on that dialog you posted the image of; which should confirm the deletion. Relying on a pause rather than checking if the dialog has appeared is where the unreliability comes charging in. The longer the delay, the more reliable it should be. But there’s always a chance your Mac will suddenly slow down, and the longer the delay the less efficient it is as you want it to be as faster than pressing enter yourself for that confirmation. but saying that, the enter and delete keys are next to one another on my keyboard, so the actuation of that sequence manually would be minimal. Probably half a second or less once it’s in my muscle memory.

Wow thanks for the extensive reply. I agree MS is not your friendly helpful company and I have had other bugs where they suggest you make that a request for the future.**

I had gone the other route like you suggest dealing with the problem with this script as an experiment. Though I do not like using keystrokes in scripts. Here a sample.

on run {input, parameters}
tell application “/Applications/Microsoft Outlook.app” to activate
tell application “System Events”
key code 51 using {shift down, command down}
key code 36
end tell
delay 1
return input
end run

As to SD it shows no errors. I tried that before. It runs and shows me at the bottom the text stopped.

PS that MS Forum post is mine.