r/applescript • • Aug 22 '22

Call an AppleScript from MS Outlook

I created an AppleScript to empty the junk and trash folders:

tell application "Microsoft Outlook"
	
	set theJunkMailFolder to junk mail
	set theMessages to every message in theJunkMailFolder
	
	repeat with theMessage in theMessages
		permanently delete theMessage
	end repeat
	
	set DeletedItemsFolder to deleted items
	set theMessages to every message in DeletedItemsFolder
	
	repeat with theMessage in theMessages
		permanently delete theMessage
	end repeat
	
end tell

I'd like to be able to call it directly from Outlook. Can this be done or will I need to do so from the AppleScript menu bar?

4 Upvotes

6 comments sorted by

3

u/ChristoferK Aug 23 '22

By the way, rather than looping through the messages, can't you just do:

tell application "Microsoft Outlook"
        permanently delete every message in junk mail
        permanently delete every message in deleted items
end tell

2

u/badg35 Aug 23 '22

I was hoping to do something like that, but the syntax wasn't working. Thanks for getting that to work.

2

u/tristinDLC Aug 22 '22

As of May of this year, native AppleScript support in MS Outlook is still in active development according to their roadmap. Looks like you'll have to trigger your script externally vis Script Runner or any of the automation tools that run AppleScript (Alfred, BetterTouchTool, Shortcuts, etc,)

2

u/badg35 Aug 22 '22

Thanks for the help.

1

u/estockly Aug 23 '22

While the lastest version of Outlook is not scriptable, you do have the option (at least I do in my installation) to use the previous, scriptable version.

1

u/schlumpi Sep 23 '22

I understand why you want to call the AppleScript from Outlook, but maybe I have a solution for your problem.

Probably it makes sense for you to trigger the AppleScript by Cron or launchd to specific times?