Home Link

Hello, my name is Brett Terpstra, and it’s nice to meet you. Elegant solutions to complex problems. Curious?

OTask: CLI for OmniFocus

OTask: CLI for OmniFocus Tagged: appscriptomnifocusruby
Jul 02, 2011 (219 days ago)

A reader named Tony left a comment on my Duplicating Safari browsing sessions post, recommending that I try out appscript for my AppleScript bridging needs. I frequently use system calls to osascript to do this, and I’ve shied away from scripting bridges in the past because they make things much harder to share and distribute. I thought I’d give it a try, though.

I like it. I like it a lot. It’s frustrating that I can’t just hand you this script without a list of requirements and dependencies, but I’m going share it anyway, just to show off some of the appscript’s capabilities.

What I built was a CLI for OmniFocus. I had an AppleScript/Ruby monstrosity that actually worked with TaskPaper, The Hit List, Things and OmniFocus, but that one got out of hand. I took the good parts of it, concentrated on OmniFocus and converted it to appscript in short time. The result is OTask.

Requirements

You need a few things before this will even think about running for you. RubyGems is a must. I still haven’t figured out if that’s part of the default OS X install or not, but if you have Developer tools, you’ve got it. Then you need the ‘rb-appscript’ gem. You also need the gems ‘chronic’ and ‘amatch’. You can install each by using gem install gemname, and you may have to run the command with sudo, depending on your system’s permissions. If you’re still on board, here are the docs, and the script is on GitHub.

Documentation

OTask uses a custom syntax to allow entry of the various elements of an action in one line of text. The following formats can be used anywhere in the line, with the exception of the flag (!) which must be the last character on the line, preceded by a space.

  • @context (fragment, no spaces)
  • #project (fragment, no spaces)
  • due(due date) (can be shortened as d(date))
  • start(start date) (can be shortened as s(date))
  • (notes)
  • ! (sets task as flagged)

Contexts and project specifiers should not include spaces. The algorithm that is used will find the best match for the string you give it, so you only need to include enough of it to distinguish it from other contexts or projects. For example, if I were going to put an action directly into my Markdown QuickTags folder, I could just use “#mdqt” and it will find it. “@corr” will get me the “correspondence” context.

Dates are entered in natural language format. You can type “tomorrow,” “in 3 days,” “next tuesday,” etc. You can also use “+3″ to set a date 3 days from the current day, “+7″ for a week, and so on.

Command line options

–h, –help Displays help message
–q, –quiet Output as little as possible, overrides verbose
–V, –verbose Verbose output
–g, –growl Use Growl for feedback

Example usage

$ otask "Write a letter to mom"

This will put a task into your inbox with the name “Write a letter to mom.” Nothing else will be set, it will wait there for you to pick it up.

$ otask -g "Pick up the kids from school @err #single due(today 3pm) !"

This creates a new task in a project called Single Tasks, with a context of “errands”, a due date of 3pm on the current day, and flags the task.

The task will go to your inbox by default, and–if provided–project and context will be set. Your settings for automatic cleanup will determine what happens after that. Task elements not specified are left unset.

The -g parameter gives us our feedback via Growl, which is handy if you’re calling it from a background script or application launcher like Quicksilver or LaunchBar.

$ otask "Brainstorm for the morning meeting (Bill had some ideas, it might be worth checking in with him this afternoon) d(tomorrow 8am) #hipstartup @think"

This will create a task with a note. Everything in parenthesis is removed from the task name and placed into the notes of the action, sans parenthesis. Note that the due date prefix can be shortened to just “d,” (and the start date prefix can be just “s”).

OTask looks for notes in parenthesis, but it can also receive piped input from other applications as a note for the task. If you wanted to include text from a file, the output of a command or the plain-text contents of your clipboard, you can just pipe the output into the command, specifying the rest of the options as usual.

$ pbpaste | otask "Notes from the morning meeting @ref"

That would take the current contents of your clipboard and make them the attached note on the “Notes from the morning meeting” task (with the context “reference”).

Calling from LaunchBar (et al.)

You can do this with any app that can run a script with input, or call it from automated scripts if you could think of a reason to. Below is the AppleScript for a LaunchBar action. Create a new script in AppleScript Editor and paste the code in. Edit the path in the last function to point to wherever you put the otask script. Save the AppleScript as OTask.scpt in ~/Library/Application Support/LaunchBar/Actions.

You’ll find the Action in LaunchBar after it indexes. Type ‘ota’ (or as much as you need to get it to come up) and then press space bar. Use the syntax shown above to write out your action and its elements, but leave out the ‘otask’ part and any parameters. Hit return and Growl (you have it installed, right?) will tell you what’s up.

on handle_string(actionString)
	if (length of actionString is not 0) then
		my runRubyScript(actionString)
	end if
	open location "x-launchbar:hide"
end handle_string
 
on runRubyScript(action)
	set res to do shell script "$HOME/scripts/otask.rb -g \"" & action & "\""
end runRubyScript

Download

https://​github​.com/​t​t​s​c​o​f​f​/​O​T​ask

Related posts:

  • Moving day
  • Things tasks from the command line
  • Totally TaskPaper
  • OmniFocus and Markdown, oh my
  • Marked 1.3 drawing winners
This entry was posted on Saturday, July 2nd, 2011 at 2:10 pm and is filed under Blog, Code.You can leave a response, or trackback from your own site. Tagged: appscriptomnifocusruby

10 Responses to “OTask: CLI for OmniFocus”

  1. spacer Patrick says:
    July 2, 2011 at 2:48 pm

    That’s the good stuff. I appreciate it that you took your time and also came up with another quality blog post. The script definitely deserves one and that way I don’t feel so guilty for stealing your time. ^__^

    Reply
  2. Macdrifter » Blog Archive » OTask says:
    July 2, 2011 at 4:55 pm

    […] love this stuff. Another OmniFocus CLI. Typical amazing and clever work by Brett Terpestra. This is the second OmniFocus CLI in the past month. Something tells me the Omni Group should be […]

    Reply
  3. spacer Lri says:
    July 2, 2011 at 6:54 pm

    Quoting Brett Terpstra a few months ago:

    I’ve been flirting with a plain-text to-do system again. The biggest problem for me is that a plain text system opens up so many possibilities for fiddling and scripting. I always end up fiddling more than working when I try it.

    I don’t really see how this is more convenient than using the quick entry dialog. But this has to be one of the most impressive uses of rb-appscript so far.

    Reply
    • spacer Brett says:
      July 2, 2011 at 11:00 pm

      It’s a long story, but as I mentioned in the post this is a short adaptation of a larger project that I abandoned. I’d agree with your convenience assessment, but it does open up good integration with LaunchBar, Quicksilver, Alfred and the like. And I’m honored to be quoted, even if it’s to contradict myself :).

      Reply
    • spacer Doug says:
      July 2, 2011 at 11:27 pm

      This is more convenient as you never have to view OmniFocus or the quick entry dialog. Works great using Alfred as well. This is fantastic Brett. Thanks!

      Reply
  4. spacer Phill says:
    July 12, 2011 at 5:20 am

    This is a great little utility. I am trying to use it from Alfred though and do not know how to either adjust the LaunchBar applescript script to make it work or how else Alfred could use it. One of the problems I have is that because OTask is seen as a Unix Executable by the OS Alfred cannot be made to ‘see’ it except from a ‘find’ command.

    If anyone can help me I would be grateful.

    Reply
  5. spacer emory says:
    July 17, 2011 at 5:24 pm

    Do you have any plans to add query/searching to OTask?

    Reply
    • spacer Brett says:
      July 18, 2011 at 2:53 pm

      Not at the current time, but I’d be happy to accept pull requests on GitHub from anyone who fleshes something like that out.

      Reply
  6. Other People Said Interesting Things: July 23rd — Another Blogger says:
    July 31, 2011 at 11:39 pm

    […] OTask: CLI for OmniFocusBrett Terpstra creates a command-line interface for OmniFocus […]

    Reply
  7. spacer Jordan Patterson says:
    January 2, 2012 at 11:43 pm

    Brett I am admit idly fairly new to unix but I really want to use this CLI with a hazel rule to auto add tasks based on a given criteria.

    I have installed xcode via the mac app store; installed the gems ‘rb-appscript’, ‘chronic’, and ‘amatch’ based on your install instructions; and dragged the otask executable into my use/bin folder.

    I am getting the following error when trying to invoke the CLI, any ideas?

    /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:in gem_original_require': no such file to load -- rdoc (LoadError) from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/rubygems/custom_require.rb:31:inrequire’ from /usr/bin/otask:33

    Reply

Leave a Reply

Click here to cancel reply.

Comments may use standard Markdown formatting


Notify me of followup comments via e-mail. You can also subscribe without commenting.

Saying…

Follow me on Twitter

spacer spacer

Markdown? spacer

marked

MultiMarkdown preview.
Everywhere.

Learn More

Looking for me elsewhere? Here's my card.

spacer
Writing…RSS
  • Introducing Gather, a Cocoa Markdownifier
  • Connecting nvALT and Address Book
  • ScrivWatcher, one more time
  • From my Macworld Diary
  • ScrivWatcher droplet, an easier live Scrivener preview
  • Preview a full Scrivener document in Marked, live
  • Web excursions: January 20, 2012 — January 24, 2012
  • A Service for writing MultiMarkdown footnotes inline
  • iOS-inspired popup box CSS
  • System Service: Clip to Day One
Listening… (last.fm)
  • Sorting…
    • Blog
    • Bookmarks
    • Code
    • Featured
    • Misc
    • Music
    • Reviews
    • Write
Thanks for reading!

Entries (RSS) and Comments (RSS), or Subscribe by Email

gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.