Converting from TaskPaper to Emacs Org-Mode

Why TaskPaper and Org-Mode?

TaskPaper is a simple and elegant task management software for the OSX platform. It combines the simplicity of a text micro-format to mark the tasks, and the elegance of a Mac UI. It also provides a quick launch time and a nice system-wide quick entry window that is accessible with a single shortcut key.

tasks.png

taskpapercapturewindow.png

I have been a heavy user of Emacs’ Org-Mode for some years now, and love the power and flexibility it offers for tracking not just outlines and tasks, but any text based item, including notes and calendar entries. In fact Org-Mode has become one of the primary software that I use regularly, every day.

So where does the link between TaskPaper and Org-Mode come in? Both are text based, and have their own light-weight formats to define outlines and tasks. The underlying files are plain text with the meaning readable even when not viewed by the appropriate software. Org-Mode is obviously much more feature rich than TaskPaper, which by design keeps things simple.

However, there is one big difference that has led me to looking at integration: Org-Mode is Emacs based and hence takes ages to launch. TaskPaper on the other hand launches in under a second, and also offers a nice quick entry form that is available system-wide via a a global short-cut key.

Emacs aficionados will protest now – after all – Emacs is meant to be launched and never shutdown! This is true, but in my usage patterns, Emacs does get closed once in a while and having to launch it just to make a few quick Org-Mode entries (even with the excellent remember mode) becomes a pain.

My usage has now become more of the following:

  1. Use TaskPaper as an initial capture mechanism (sort of as a pre-Inbox store). I make heavy use of the quick entry window here
  2. Use a script to collect the TaskPaper entries and reformat them into a Org-Mode compatible file
  3. Append the converted entries into my primary Org-Mode Inbox whenever I have Emacs open

This (for me) provides best of both worlds – quick and ubiquitous data capture, and the power and flexibility of Org-Mode.

The Ruby Conversion Script

Without further ado, the script to convert from TaskPaper to Org-mode is:

#!/usr/bin/env ruby
#
# Converts Taskpaper files to Emacs org-mode files.
#
# Author: Anupam Sengupta, 2010
#
# Distributed under the BSD license (<a href="http://www.opensource.org/licenses/bsd-license.php">http://www.opensource.org/licenses/bsd-license.php</a>)
#
# Usage: From the command line, enter the command:
#
#  ./tpaper2org.rb &lt;taskpaperfilename&gt;
#
# The output is on STDOUT, which can be redirected to an Org-mode file.
# Whether the generated org-mode file should use odd-level prefix stars
# See <a href="http://orgmode.org/manual/Clean-view.html">http://orgmode.org/manual/Clean-view.html</a> for details.
ORG_USES_ODD_LEVELS = false

LINE_PATTERN = /^(\t*)          # Leading tabs
               -                # Followed by a dash (the taskpaper task identifier)
               (.*?)            # The task description
               ((@\w+\s*)*)     # The tags, if any
               $/x

all_tags = Hash.new(0)

Shiftlvl = ORG_USES_ODD_LEVELS ? 2 : 1 # Determine the number of stars to use in Org-mode entries

while (line = gets()):
  line.chomp!
   md = LINE_PATTERN.match(line)          # Match and extract each line
  if md then                                                # ................ A Task line
    tags = md[3].split(/ +/).reject {|tag| “@done” == tag } # get the tags, except @done tags
    tags = [‘’, tags, ‘’].flatten unless tags.empty?
    puts ‘*’ * (1 + Shiftlvl * (md[1].length + 1)) + (line =~ /@done/ ? “ DONE” : “ TODO”) + md[2] + tags.join(‘:’)
    tags.each { |tag| all_tags[tag] += 1} if tags # Keep a list of all tags
  elsif line =~/:$/                               # ................ A project line
    print “* “
    puts line.chomp(“:”)
  else                          # ................ Any other line
    puts line
  end
end

# Lets do a summary of the tags used.
puts &lt;&lt;END
# The tags used till now.
#+TAGS:#{all_tags.keys.sort.join(‘ ‘)}
END

Note that Org-mode supports multiple prefix styles with ‘*’. In particular, the odd-levels versus the odd-even levels is interesting and useful. The script has a ‘ORG_USES_ODD_LEVELS’ global variable that can be set to true if this is the desired export format.

In addition, the script also adds the tags used in the TaskPaper file as a ‘#+TAGS’ entry in the exported org-mode file. You can comment this if this is not required.

The TaskPaper format

The TaskPaper format is simple, and the file (which by default ends with the extension ‘.taskpaper’) is essentially a plain text file that can be opened and edited in any text editor.

The format can be summarized as (from the TaskPaper User’s Guide):

A project is a line ending with a colon:

      A Project:

A task is a line starting with a dash followed by a space:

    - My First Task

A Note is any line that is NOT a project or a task (i.e., does not start with a dash or end with a colon):

    Notes for a task

A tag is any word prefixed with the @ symbol. The tag can optionally have a value in parentheses after the tag name:

      - My First Task @atag @another_tag(1)

Outlining is done by indenting the tasks with tabs:

     - My First Task @atag
         - My sub-level task

Usage

Using the script is simple. Assuming that TaskPaper’s file is named tasks.taskpaper, from the OS X terminal, run the following command:

        $ tpaper2org.rb tasks.taskpaper >> tinbox.org

Where tinbox.org is the destination org-mode file.

This shell command can be put into a cron job or invoked from within Emacs to pull in the tasks as required. You may also want to delete the TaskPaper file (or empty its contents) after this is done, to prevent duplicate entries being imported the next time the Ruby Script is run.

Links

taskpaper.el is an Emacs mode for emulating the TaskPaper interface with support for projects and tasks. The tags support seems to be missing.

Discussion on the Org-Mode mailing list about Taskpaper and Org-Mode.

About these ads

14 Comments on “Converting from TaskPaper to Emacs Org-Mode”

  1. Ryan says:

    If the emacs startup time is too long, look into running emacs as a daemon and then using emacsclient. Then your emacs window will come up instantly. I’m not sure how to do this on OSX, but I assume that it’s possible.

    • evolve75 says:

      It is definitely possible and is actually easy to setup as well. However, the problem is that in emacs –daemon mode, the GUI specific settings in .emacs are not applied consistently (as there is no window frame available when emacs starts up in the daemon mode).

      This is too much of a hassle for me to fix. Hence the avoidance of –daemon.

      I do use emacsclient whenever Emacs is running – and this works beautifully.

      • Ryan says:

        M-x describe-variable after-make-frame-functions

        You could put GUI-specific settings in there. Of course, then you have to do all the work of figuring out which settings are GUI-related.

        In any case, you might still be interested in the -a option of emacsclient. Using that, you can either start a new instance or open a file in the existing instance as appropriately.

  2. Pierre says:

    Why not –daemon on emacs23 (+ emacsclient) ?
    I usually start emacs with my session and that’s it – emacs is then always ready to rumble :-)
    (cf http://www.emacswiki.org/emacs/EmacsAsDaemon)

    • evolve75 says:

      Hi Pierre,

      See my comment above on -daemon mode. Basically, the window/frame specific settings do not get applied as Emacs does not have a window context when starting as a daemon. This is a non-starter for me.

      • Pierre says:

        Hi,

        I use different color themes in X and in console, so I must tell emacs to do different things … and it works quite well with deamon (after setting color theme to !cumulative/!global) – The only trick is to add an hook to run a dedicate func on frame creation time:
        ;; snip
        (add-hook ‘after-make-frame-functions ‘do-something-nice)
        ;; snip

        Maybe it can help, maybe not – just wanted to be ‘complete’ :-)

  3. […] This post was mentioned on Twitter by Jesse Grosjean, のどっち (list '原村 '和). のどっち (list '原村 '和) said: Converting from TaskPaper to Emacs Org-Mode > http://slashusr.wordpress.com/2010/03/30/converting-from-taskpaper-to-emacs-org-mode/ […]

  4. Aaron says:

    There’s a lot you can do with some simple AppleScript. For example, check out: http://github.com/claviclaws/org-mac-protocol/blob/master/org-mac-protocol.org

    That should do most of what you want and more.

  5. evolve75 says:

    Hi Aaron,

    Thanks for sharing this. I do use org-mac-protocol (especially to clip and store links from Safari). Unfortunately it does not work with Firefox (due to a Firefox problem).

    But a good solution overall.

  6. Oscar says:

    Hm, sounds like someone needs to take a look at their .emacs – mine starts (and I have loads and loads of unnecess……ehr, optional, modules installed) in ~1 s on my iMac and ~2 s on my cheap netbook. Take a look at the following blog post, it’s a good start for understanding why emacs takes a lot of time to start:

    http://a-nickels-worth.blogspot.com/2007/11/effective-emacs.html

    And C-u 0 M-x byte-recompile-directory RET is pretty awesome, too :)

  7. Hm, some wordpress magic is converting the quotes in the ruby source into nasty other characters. Is there any chance you could put the script into a gist?

  8. […] The busiest day of the year was March 30th with 408 views. The most popular post that day was Converting from TaskPaper to Emacs Org-Mode. […]

  9. tristancollins155071068 says:

    I had issues getting this to work by copy – paste (characters getting messed up), and the gist is unavailable. So here is my tidied up code that works for me:

    http://pastebin.com/49ihzJmm


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 67 other followers