Omnifocus and Setting Contexts

omnifocus

#1

Using omnifocus 2.0 and would love to create something in KM that lets me quickly add context to tasks. Adding keyboard commands (tab tab tab + type phrase + return) is clunky; anyone else had success doing it?


#2

Scratch that, I think I figured it out. Use this AppleScript and create a new one for each context name.

property context_name : "errands"

tell application "OmniFocus"
   tell front document
      
      -- GET CONTEXT
      set lst_contexts to every flattened context whose (name = context_name)
      
      tell content of document window 1
         set SelectedTasks to value of every selected tree
         if ((count of SelectedTasks) < 1) then
            display alert "You must first select an item to complete." as warning
            return
         end if
      end tell
      
      if (length of lst_contexts) > 0 then
         set the_context to (item 1 of lst_contexts)
      else
         -- CONTEXT NOT EXISTS; CREATE CONTEXT
         set the_context to (make new context with properties {name:context_name})
      end if
      
      repeat with anItem in SelectedTasks
         set context of anItem to the_context
      end repeat
      
   end tell
   
end tell