Outlook in Office 365 Applescript to delete message no longer working.

I just upgraded to 365 from 2011. The script below worked fine in 2011 for permanently deleting messages from Outlook. It stopped under 365. I tinkered with it but cannot get it to work under 365. Does anybody see what it could be?

tell application "Microsoft Outlook"
	set theMsgs to the current messages -- selected messages
	try
		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
		beep
		display dialog errMsg & return & return & errNum & return & return & "(Erroring on message: " & theSubject & " in " & theFolder & ")" with icon 2
	end try
end tell

Thanks

First thing to do, from the Script Editor, look at the dictionary of the application.

The instruction below is supposed to trigger a function whose “old name” is no longer recognized.

 set theFolder to name of «class stor» of theMsg

It’s the only useful info given in your message.

Would help to give us more by running this edited version

tell application "Microsoft Outlook"
	set theMsgs to the current messages -- selected messages
	log result
	try
		repeat with theMsg in theMsgs
		log theMsg
			permanently delete theMsg
			log "Point 05"
		end repeat
	on error errMsg number errNum
	log errMsg &", number: "&errNum -- was a typo here
		set theSubject to subject of theMsg
		log  "Point 06"
		log theSubject
		set theFolder to name of «class stor» of theMsg
		log  "Point 07"
		beep
		display dialog errMsg & return & return & errNum & return & return & "(Erroring on message: " & theSubject & " in " & theFolder & ")" with icon 2
	end try
end tell

and return here the complete log history returned by the Script Editor

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 25 juin 2020 15:57:56

Hi ChangeAgent: This script works for me on Mojave 10.14.6 and the current 365 with an Exchange account.

Morning Yvan sorry for the delay, but here all hell is loose.

here is the result of your script.

tell application "Microsoft Outlook"
	get current messages
		--> {}
	(**)
end tell

strange, as it refuses to do anything here.

I’m not sure of what mean “current message” in Outlook idiom.
Is it an open message or is it, as you commented a message justv selected in a viewer ?

Had you really open (or select) at least one message before running the script ?
If you didn’t, such result is normal.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 27 juin 2020 16:46:28

Outlook open, select a message, run script, no result.

yes I did, that is how the script worked in the past. select message, run script, messages nuked.

I don’t know Outlook.
What is really selected, an opened message or a row describing a message in a viewer.

One more time you ask about a problem striking on your machine but not of an other one.
I may be wrong but my first idea is that you aren’t putting the app in the correct setting required to get the script working.
It may also due to a script wrongly saved as it was in a long thread some times ago.

Given what I see here and there on the web

the selection
and
current messages
aren’t containing the same objects.
It would help to send to my mailbox:
(1) a screenshot displaying what is selected when you execute the script
(2) the exact script which you used so that I may check that it’s a clean one.

You may also look at the prefpane dedicated to Privacy.
In mine, Mail is listed among the apps allowed to control the computer.
Is Merdosoft Outlook listed on your’s ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) samedi 27 juin 2020 18:24:19

I send you the stuff Yvan.

Yvan, greetings

Merdosoft is allowed indeed.

Not sure what you mean there?

Morning, I was testing today and indeed the old/original script worked for me two or three times and stopped working. Did you test more than once? Would you mind testing again?

this is the result I get when running it if it does not work.

tell application "Microsoft Outlook"
	get current messages
		--> {}
end tell

Hi. Still works. When no msg is selected, you will get the empty brackets result. If one or more messages are selected, you will get a list of their references (eg,

{incoming message id 58443 of application "Microsoft Outlook", incoming message id 58409 of application "Microsoft Outlook"}

when two msgs are selected.

Since you’re running a repeat loop that deletes msgs, it is expected that when all msgs have been deleted, the last repeat will produce an empty list.

You could add some code to test for how many msgs remain (whether the remaining count is 1 or greater), and if none remain, then exit the repeat.

Browser: Safari 605.1.15
Operating System: macOS 10.14

Kerflooey thanks for testing, reporting and good morning.

It is indeed a strange phenomenon.

First of I am running the script Yvan send me in a private mail.

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

First I always only try to delete one message at the time. And, as I am not a master scripter, I would not know how to do this.

There is another interesting phenomenon, like this AM I wanted to make a QuickTime movie to post how it does not work. As this might help us solve it. As soon as I start QT the script starts working.

Anyway we plough on as somewhere and somehow it must work as intended.

PS here the error message I get in the log

tell application "Microsoft Outlook"
	get selection
		--> outgoing message id 7104
	(*outgoing message id 7104*)
	count outgoing message id 7104
		--> 1
	(*item 1 of outgoing message id 7104*)
	permanently delete item 1 of outgoing message id 7104
	(*Point 05*)
end tell

I am still struggling with this one.

I simplified the script to bare bones and it still gives me the same error.


tell application "Microsoft Outlook"
	set theMessages to the selection
	repeat with theItem in theMessages
		permanently delete theItem
	end repeat
end tell

I get:

error "Microsoft Outlook got an error: item 1 of calendar event id 1198 doesn’t understand the “permanently delete” message." number -1708 from item 1 of calendar event id 1198

and yes no calendar event is selected, I select a mail message!

getting desperate i wonder if there is anybody who has an idea as to why this happens? how to fix? etc.

What a mess.

What you report is not an error message, it’s the log history returned by a script which behaved flawlessly.
If an error stroke you would have seen its message, its number, {Point 06), the subject of the message, (Point 07)

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 juillet 2020 11:43:22

I’m desperate. How may you imagine that Outlook report a selected calendar event if you don’t select such item ?
I hate Merdosoft but their products do more or less what they are designed for without any form of fantasy or imagination.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 juillet 2020 11:50:54

well I am not the biggest MS fan either. but I am stuck with it for compatibility reasons.

could it be the mac somewhere? see I am not always able to recreate the problem and get sometimes different results on different machines.

see now on one machine when I run the script it opens the message.

You are the only one supposed to be able to know what you did on these different machines and which are the settings of the application and the system on these machines.

Don’t worry but, from my point of view, as I already wrote, the explanation of the selection of calendar event is somewhere between a chair and a keyboard, not in the code of the used application.
Alas it’s clear that if you don’t know what you did I doubt that somebody here will be able to guess that.

You may ask Uncle Donald T, maybe he is aware of a chinese gremlin able to corrupt your machine.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) mardi 7 juillet 2020 19:55:14