AppleScript, Microsoft Outlook and kMDItemDueDate

This is a bit of an arcane question, but hoping someone has some experience to help.

I have an AppleScript routine I’ve used for some time that I use to triage email. The script presents a variety of choices, including commands to set the follow-up dates for a message. The script uses UI commands to choose items from the contextual Microsoft Outlook “Follow-Up” menu that presents when command clicking on an Outlook message.

This is married with an Outlook Smart Folder that shows me messages flagged as due today or earlier. The data element the Smart Folder references for due date is kMDItemDueDate.

This all works fine.

Here’s the problem I’m facing. I’ve re-written the applescript to directly set the due date for the message rather than going down the UI scripting path. See script snippet below. The steps I’m referring to follow the set theDoLaterFolder... line

The script is working as expected in terms of due date (and other message attributes… eg destination folder) being set correctly. I can see the new due date in Outlook when I look at the message. However, it seems the internal kMDItemDueDate is not getting set.

kMDItemDueDate is set when choosing the “Follow-Up” flag from the Outlook UI. It does not appear to get set when manually updating due date via AppleScript. At least that is my supposition after extensive troubleshooting.

If kMDItemDueDate is not set, the smart folder rule will never fire.

Assuming that makes sense, any ideas on forcing a value to kMDItemDueDate?

AppleScript snippet for inbox triage
    tell application "Microsoft Outlook"
    	set theSelectedMessage to selected objects
    	repeat with theMessage in theSelectedMessage
    		set theAction to text returned of (display dialog "Archive, Search or Days" default answer "")
    		if theAction is "false" then
    			if theAction = "S" then
    				my doSearch(theMessage)
    			else if theAction = "A" then
    				set theArchiveFolder to folder "2019" of folder "Inbox" of account of theMessage
    				set is read of theMessage to true
    				set todo flag of theMessage to not flagged
    				move theMessage to theArchiveFolder
    				set theDoLaterFolder to folder "Do Later" of folder "Inbox" of account of theMessage
    				set is read of theMessage to true
    				set todo flag of theMessage to not completed
    				set due date of theMessage to ((current date) + theAction * days)
    				move theMessage to theDoLaterFolder
    			end if
    		end if
    	end repeat
    end tell

In case you are interested, the following is the raw query used for the Smart Rule (again, this rule works as expected when a message is flagged via the Follow-Up menu — either direct or through UI scripting). It does not work when due date is set via the script.


You ought to contact Microsoft and let them know this, as it’s something that would occur in the lines of code that make up the Outlook application. Clearly they’ve bound the menu item to a function that writes the metadata for the file. They must not have done the same for the AppleScript property.

But very well done for evolving your script and purging the UI scripting guff. To help you commit to the transition, I believe there are AppleScriptObjC methods that allow you to get and set metadata items. I’ll have to dig out what I have when I get home later, but I think the class NSMetadataItem is the one of interest. thanks for the response. I would enjoy seeing whatever info you have on the AppleScriptObjC option. I have not done anything with that and would love to learn. Not to mention resolving my current problem.

Thanks in advance for any reference you can point me to. Cheers! — jay

well… in the spirit of “always learning”, my supposition above may be wrong. After some more googling I realized I could run the MDLS command with an Outlook message to inspect attributes. In doing that it looks like kMDItemDueDate is getting set, but the time is off.

Looks like I need to do some more script work.

Sharing this to avoid any other work on the part of others to provide other info.

that was the problem. That is, choosing Follow-Up date from the contextual menu defaults midnight to the due date. My direct method was setting the current time to the due date. As such, the logic of the Smart Folder was failing. I’ve modified the AppleScript to force midnight with the due date and it seems to be working now.

Sorry for the “noise” with this post.

1 Like

No, I think this is useful information for others to benefit from. Thanks for this.