×

OmniFocus: New Task for Selected Mail Message

This “macOS only” shortcut uses an AppleScript script to extract information about the currently selected Mail message, and pass it to the shortcut as a Dictionary.

The passed data is then used to create a new task in OmniFocus with the subject of the selected Mail message becoming the title of the created task. In addition, a link to the selected Mail message is placed in the note of the newly created task.

DOWNLOAD SHORTCUT

 1  “Run AppleScript” action • This action for macOS Shortcuts app enables the execution of the provided AppleScript script.

 2  AppleScript Script • This script locates the selected Mail message and creates and returns a record (dictionary) of two message properties: subject and the message’s message id as a URL (link).

 3  Dictionary • This action converts the passed AppleScript record into a dictionary usable by Shortcuts.

 4  “Open App” action • Makes OmniFocus the active application.

The “New Task for Selected Message” shortcut

 5  “Add Item” action • This action is used to create a new OmniFocus task in the inbox. The Mail message subject is passed as the title of the new task.

 6  Message Link • The link to the Mail message becomes the value of the note of the new task.

 7  “Show Item” action • Selects and displays the created task in the OmniFocus window.

AppleScript: Pass Dictionary of Selected Message


tell application "Mail" set msgs to selected messages of front message viewer if (count of msgs) is 1 then set selMsg to item 1 of msgs set msgID to message id of selMsg set msgURL to "message:%3C" & msgID & "%3E" set msgTitle to subject of selMsg return "{\"msgURL\":\"" & msgURL & "\",\"msgTitle\":\"" & msgTitle & "\"}" else activate display alert "Selection" message "Please select a single Mail message." buttons {"OK"} error number -128 end if end tell