I'm seeing some weird categorization behavior on Outlook 2016 on El Capitan.
In the GUI's Category list, there's a category called, say, "Category1", with the color red. When I use the GUI, that category gets applied correctly.
But when I use AppleScript to apply the "Category1" label, a different color is applied, and there's no checkmark next to "Category1" in the GUI. It's like there are two categories with the same name, and AppleScript and the GUI are pointing to different ones.
Has anyone else seen this, or have a fix?
Thanks.
Updated: Here's a code snippet showing how I'm using AppleScript. Also, note that many of my categories are imported from a Windows PST file.
tell application "Microsoft Outlook"
-- get the currently selected message or messages
set selectedMessages to current messages
-- if there are no messages selected, warn the user and then quit
if selectedMessages is {} then
display dialog "Please select a message first and then run this script." with icon 1
return
end if
repeat with theMessage in selectedMessages
set categoryList to get categories of theMessage
set cleanCategoryList to {}
set wasCategoryRemoved to 0
repeat with theCategory in categoryList
if name of theCategory is "Category1" then
set wasCategoryRemoved to 1
else
set end of cleanCategoryList to theCategory
end if
end repeat
if wasCategoryRemoved is 0 then
set end of cleanCategoryList to category "Category1"
end if
set categories of theMessage to cleanCategoryList
end repeat
end tell
Best Answer
I had the exact same issue. I was able to resolve by applying the exact category id I wanted like:
Rather than like:
Here is how I got the category ids. I selected a message in Outlook that had only the category I wanted and then ran this script manually from Script Editor:
I then used the returned category id in the code below to set messages to this category in the future (I cobbled this together from many sources online over time, so unfortunately it's not easy for me to give credit to the right folks):
I hope that helps someone else looking for a solution to adding a category to selected Outlook emails with AppleScript.
A great improvement would be removing the first manual step of getting the desired category id, and instead allowing setting category via the textual name of the category, looping through all existing categories in Outlook until you find it, and then applying that id to the selected emails. I'd be grateful if anyone improved my version this way and shared it.