Removing duplicates from OmniFocus

| | Comments (0)

Sometimes something (I suspect iSync) screws up and duplicates my tasks. This has proven useful:

tell application "OmniFocus"
  tell first document
    repeat with aContext in contexts
      set toDelete to {}
      set seen to {}
      repeat with aTask in tasks of aContext
        if seen contains name of aTask then
          set end of toDelete to id of aTask
        else
          set end of seen to name of aTask
        end if
      end repeat

      repeat with aTask in toDelete
        try
          delete (task id aTask)
        end try
      end repeat
      count of toDelete
    end repeat
  end tell
end tell

Leave a comment