This Week's Sponsor:

Kolide

Ensures that if a device isn’t secure it can’t access your apps.  It’s Device Trust for Okta.


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.

Unlock More with Club MacStories

Founded in 2015, Club MacStories has delivered exclusive content every week for over six years.

In that time, members have enjoyed nearly 400 weekly and monthly newsletters packed with more of your favorite MacStories writing as well as Club-only podcasts, eBooks, discounts on apps, icons, and services. Join today, and you’ll get everything new that we publish every week, plus access to our entire archive of back issues and downloadable perks.

The Club expanded in 2021 with Club MacStories+ and Club Premier. Club MacStories+ members enjoy even more exclusive stories, a vibrant Discord community, a rotating roster of app discounts, and more. And, with Club Premier, you get everything we offer at every Club level plus an extended, ad-free version of our podcast AppStories that is delivered early each week in high-bitrate audio.

Choose the Club plan that’s right for you:

  • Club MacStories: Weekly and monthly newsletters via email and the web that are brimming with app collections, tips, automation workflows, longform writing, a Club-only podcast, periodic giveaways, and more;
  • Club MacStories+: Everything that Club MacStories offers, plus exclusive content like Federico’s Automation Academy and John’s Macintosh Desktop Experience, a powerful web app for searching and exploring over 6 years of content and creating custom RSS feeds of Club content, an active Discord community, and a rotating collection of discounts, and more;
  • Club Premier: Everything in from our other plans and AppStories+, an extended version of our flagship podcast that’s delivered early, ad-free, and in high-bitrate audio.