Send Favorite Tweets To OmniFocus’ Inbox

In my daily “social networking workflow”, I use the “favorite” feature of Twitter as a todo list of sorts. I couldn’t find a way to add favorites to OmniFocus without leveraging email as a bridge, so I built a solution myself.

Using IFTTT, a single line of bash, Hazel, and AppleScript, I created a simple way to turn a favorite tweet into an OmniFocus task in the application’s inbox, ready for future processing. As an extra, I have also created a more “advanced” version that adds Automator to the mix to only extract URLs from favorite tweets.

IFTTT

There are ways to run your own Twitter archive tool, but I decided to rely on IFTTT, which in my experience has been reliable and sufficiently fast (supposedly, Premium accounts will someday bring even faster trigger times). Instead of forwarding a favorite tweet via email and have Mail.app process it as an OmniFocus task, I chose a different path: a tweet is turned into a text file, which then becomes an inbox task. This cuts Mail.app out of the equation, uses Dropbox and interfaces directly with OmniFocus through AppleScript, and it allows you to keep an archive of favorite tweets as plain text files if you want to.

On IFTTT, build a recipe that creates a new text file in Dropbox for every new tweet you mark as favorite. To make things simpler, I set a separate destination folder in my Dropbox, and chose a basic username/text syntax. You can tweak these parameters however you want to; this is how tweets will show up in OmniFocus, so feel free to choose the syntax you prefer.

Process Text

On the Mac, we have to monitor the destination folder for new text files, then execute some actions. For this — as usual — I use Hazel. Create a new rule for the folder as pictured below, then attach a shell script action and an AppleScript one.

The shell script will take the currently processed file, read its contents, make sure they’re encoded in UTF-8, and copy the text to the system clipboard.

cat $1 | textutil -convert txt -stdin -stdout -encoding UTF-8 | pbcopy

The AppleScript will take the clipboard, and make a new inbox task in OmniFocus out of it.

set OFTask to the clipboard

tell application "OmniFocus"
	set theDoc to first document
	tell theDoc
		make new inbox task with properties {name:OFTask}
	end tell
end tell

Last, you can insert an action to archive or delete the text file. Obviously, keep in mind that OmniFocus will have to be running to receive new inbox tasks. If you fiddle around with the AppleScript, you could also set a default context and project for new tasks, but I prefer to keep them in the inbox for a proper review.

The Slightly More Complex Way: Extract URLs

If you, like me, use Twitter favorites as a todo list/cool-things-I-have-to-check-out list, it’s likely that you’re doing so for the links shared in your timeline. Wouldn’t it be neat to have our Mac automatically extract the URLs from tweets, and only save those in OmniFocus?

I created an Automator workflow that extracts URLs from text, and passes them to the clipboard and to the same AppleScript we’re using above. The workflow works fine with single-URL tweets, but it works even better with tweets that have multiple URLs: in that case, it’ll extract the URLs, and it will combine text strings with a Return delimiter (you can customize it to your own liking).

For some reason, Apple’s own “Extract Data from Text” Automator action doesn’t play nicely with URLs in plain text files. To accomplish this — and a whole lot more actions — I use the Text Automator Action Pack by Automated Workflows, a $15 collection of great text-related actions that you can check out here. Their “Extract URLs from Text” action works perfectly, and it even lets you add more URL Search prefixes.

You can go crazy with the formatting of links here. I keep it simple, but you can add prefixes to new lines (say, “Link – “), suffixes, or remove leading or trailing characters from text. It’s all included in the Action Pack.

We’ll have to put the Automator Workflow between the shell script and the AppleScript. For convenience and organization, I let Keyboard Maestro run the workflow and I call it up with these three strings at the very beginning of the script.

tell application "Keyboard Maestro Engine"
-- Tells KM to execute script as macro
	do script "Extract"
end tell

set OFTask to the clipboard

tell application "OmniFocus"
	set theDoc to first document
	tell theDoc
		make new inbox task with properties {name:OFTask}
	end tell
 end tell

Thanks to Automator, in case of tweets containing multiple links, you’ll end up with a single list of URLs in your OmniFocus inbox.

Update: Also by Automated Workflows, here’s an action that you can use to confirm the execution of the workflow in Notification Center.