Add TFS Work Tickets to OmniFocus

At work we use Microsoft Team Foundation Server to assign tasks & work tickets. When someone assigns me a work ticket I get an email with a subject like ‘so and so assigned you work ticket 12345 – fix some bug’. It would be really useful if they could be automatically added as a task to OmniFocus.

I looked at OmniFocus’ mail rule for creating new tasks, but unfortunately it won’t work with TFS work ticket notifications because it requires a specially formatted email.

Using that script as an inspiration, I came up with this script that creates a new task with the message linked to the note field. I’m sharing it just in case anyone else finds it useful.

First you’ll need to create a mail rule that filters messages matching the criteria of the subject ‘assigned you work ticket’ and the TFS notification email address as the sender.

Mail Rule.jpg

Here’s the mail action script:


using terms from application "Mail"

	on process_message(theMessage)
		tell application "OmniFocus"
			log "OmniFocus calling process_message in MailAction script"
		end tell
		set theSubject to subject of theMessage
		set p to offset of "Work Ticket" in theSubject
		set theSubject to characters p through end of theSubject as string
		set theText to "message:%3C" & message id of theMessage & "%3E"
		tell application "OmniFocus"
			tell default document
				set ctx to context "Work"
				make new inbox task with properties {name:theSubject, note:theText, context:ctx}
			end tell
		end tell
	end process_message

	on perform mail action with messages theMessages
		try
			set theMessageCount to count of theMessages
			repeat with theMessageIndex from 1 to theMessageCount
				my process_message(item theMessageIndex of theMessages)
			end repeat
		on error m number n
			tell application "OmniFocus"
				log "Exception in Mail action: (" & n & ") " & m
			end tell
		end try
	end perform mail action with messages
end using terms from

1 thought on “Add TFS Work Tickets to OmniFocus”

  1. Many Thanks for the Script, I currently use Omnifocus and did not know this was even possible – this really opens a lot of doors for further exploration on my part.

    Reply

Leave a Comment