3

A solution in search of a question. Not a big fan of how categories are assigned in the Outlook interface with all the mouse moving and stuff, so how to make it work with Applescript?

To that question I created this Applescript to allow you to assign multiple categories to selected messages and then the messages are moved to the folder corresponding to the year the message was sent.

display dialog ("Enter Category...") ¬
    default answer "" buttons {"Tag & Move", "Tag", "Cancel"} default button "Tag & Move"
copy the result as list to {the myCategories, the myTagButton}

if myTagButton is "Cancel" then
    return
end if

--- Get comma separated string and convert to list
set old_delimiters to AppleScript's text item delimiters
set AppleScript's text item delimiters to {", "}
set category_list to text items of myCategories
set AppleScript's text item delimiters to old_delimiters

--- Set category to each item of list
tell application "Microsoft Outlook"

    --- The set category needs a special list to work with multiple tags...
    --- Create a list {category "tag1", category "tag2", ...}
    set my_categorylist to {}
    repeat with categoryitem in category_list
            set end of my_categorylist to category categoryitem
    end repeat

    --- apply the list of categories to all selected messages
    --- set category of (item 1 of (get current messages)) to my_categorylist
    set msgSet to current messages
    if msgSet = {} then
        error "No messages selected. Select at least one message."
        error -128
    end if
    repeat with aMessage in msgSet
        set category of (item 1 of aMessage) to my_categorylist
        --- Move the message if so told by first dialog
        --- I file by year, so get the date the message was sent and move it there
        if myTagButton is "Tag & Move" then
            set theDate to time sent of aMessage
            set theYear to year of theDate as string
            move aMessage to mail folder theYear
        end if
    end repeat
end tell

Categories are entered in the dialog box as "foo, bar" without the quotes. Script will crap out if one of the categories doesn't exist prior to running.

Todd Vanyo
  • 545
  • 5
  • 15
  • You should post the script as an answer to the question, and then mark it as the accepted answer. Otherwise the question will remain in the unanswered queue forever. – Greenonline Jan 24 '21 at 14:39

1 Answers1

0

I know this is old, but there's a small problem with the script.

This line:

copy the result as list to {the myCategories, the myTagButton}

has the parameters backwards and should be

copy the result as list to {the myTagButton, the myCategories}

What would be even more useful is to pick the categories from a list based on the categories available in Outlook.

Greenonline
  • 1,330
  • 8
  • 23
  • 31
Swami
  • 1
  • I have found that I have had to change that line twice, there is some inconsistency over the years. I agree that having a list of all the categories would be nice, but Microsoft hides that in the cloud. And the latest version of Outlook 365 doesn’t even support AppleScript. That someone may be using this 7 years later makes me happy, however. – Todd Vanyo Jan 23 '21 at 20:26