SilverService and Taskpaper
A couple of days ago someone on the Taskpaper forum posted a feature request: “How many of us would like the projects to be sortable taking all children along. I would!”
That sounds interesting, I thought. The gears immediately began to click into place. Sort text; Mac GUI application; text editor. The slot machine came up SilverService, Perl, and the Mac OS X services menu.
Taskpaper formats its display differently than a text editor does, but at its heart it is a text editor. That makes it a perfect target for command-line services.
So far, I’ve posted a Python bridge between Django and Taskpaper and a PHP script for web display of Taskpaper documents. Either of those scripting languages would allow sorting by project. However, when I look at a problem I look at it in terms of which tool is most suited to it rather than, how can I force this tool to solve it. In this case the problem is basically a text filter, something Perl excels at.
I’m going to describe the solution step-by-step using SilverService and Smultron. SilverService is a very cool way of taking command-line programs and turning them into services under the Services menu.
The problem is, how to sort by project when each project is also followed by notes and tasks that must remain with their project.
Here is the script:
[toggle code]
- #!/usr/bin/perl
- #sort a Taskpaper-style task list alphabetically by project
- #compile the list of projects
-
while (<>) {
- chomp;
-
if (/^(.*):$/) {
- $project = $1;
- $projects{$project} = "";
-
} else {
- $projects{$project} .= $_ . "\n";
- }
- }
- #display the projects sorted alphabetically
-
foreach $project (sort keys %projects) {
- print $project, ":\n" if $project;
- print $projects{$project}
- }
Paste that script into Smultron. Save it in a folder called “bin” in your home directory. Name it “sortProjects”. You may have to “Create folder” to create the “bin” folder.
After you’ve saved it, pull down Smultron’s “Tools” menu, go to “Commands”, and then “Other”, and choose “Make executable”. A blank window will come up if everything goes okay; dismiss it.
Since SilverService services are command-line programs, it can help to test them through the command line. Open the Terminal program and type “bin/sortProjects”. When you press “return”, you should just get a blank line back. Type:
- House:
- - Fix garage roof
- - Replace kitchen cabinets
- Blog:
- - Complain about Word
- - Post photos of pets
- - Post photos of children
- - Post photos of children and pets
Press return at the end of each line; if you copied and pasted, make sure you press return after the last line. Note that this project list is not in alphabetical order. Type Control-D, and the script will sort the projects while keeping the tasks intact beneath each project:
- Blog:
- - Complain about Word
- - Post photos of pets
- - Post photos of children
- - Post photos of children and pets
- House:
- - Fix garage roof
- - Replace kitchen cabinets
If the script doesn’t return the projects sorted like that, you’ll want to fix the script before going any further. Once the script is working, you can set up a service in SilverService using it.
Go into SilverService and open its Preferences. Choose the “Add Service” button. For service name, call it “Sort Taskpaper Projects”. For shell command, type “/Users/YOURHOMEDIR/bin/sortProjects”. For input, choose “stdin”, and for output, choose “service”. Close the preferences window.
If this is the first time you’ve used SilverService, you may have to log out and log in again. You should then have a “SilverService” submenu in your Services menu. These services will work in any service-supporting application, such as Safari, Smultron, Nisus Writer, or Taskpaper.
If you paste the same project lines for House and Blog into Taskpaper, and select those projects and tasks, you can sort them by project name by choosing the “Sort Taskpaper Projects” service item.
SilverService works with any command line program, whether they are scripts you write or commands built in to Mac OS X.
- SilverService
- “SilverService is a Mac OS X application that allows you to use familiar unix shell commands from within any Services-aware application (i.e., almost any Cocoa application).” This is a very useful application if you do command-line scripting but also work in the GUI.
- Taskpaper
- At first glance it doesn’t seem like you’d want to pay $20 for a task manager this simple—but a lot of people are. Sometimes, simplicity is worth paying for.
- Smultron: Peter Borg
- “I’ve always thought that there has been a need for a free text editor on Mac OS X where you can change the current document quickly, has a toolbar, encodings support, authenticated saves and syntax colouring, split window etc.”
More Perl
- Nisus HTML conversion
- New features in Nisus’s scripting language make HTML conversion almost a breeze.
- Nisus “clean HTML” macro
- The Nisus macro language is Perl; this means we can use all of Perl’s strengths as a text filter scripting language in Nisus.
- Perls before Swine Perl tutorial
- I’ve completely revamped my Perl tutorial, and explicitly released it under the Gnu FDL. This tutorial starts from a simple filter that does nothing but echo to the terminal window, and ends with the ability to split data according to fields and import data into a SQLite database.
- Representing code in HTML
- A minor epiphany that may not be new to others on how to display programming and HTML code in HTML.
- Perl Cookbook
- This is probably the most useful Perl book I own. Whenever I need a solution quickly--which is often here at the University--I am very likely to find my start in the Perl Cookbook.
More Mac OS X tricks
- Stack windows on top of each other
- If you want to stack multiple windows directly on top of each other, it’s easy to do in any well-behaved application, such as Nisus Writer Pro, Safari, Mail, and even older applications like AppleWorks 6 and Microsoft Word X.
- Leopard setuid and passwd file changes
- Leopard Server introduced two major changes to two lesser-used features: setuid root script wrappers and BSD flat file authentication.
- Media duration in Python on Mac OS X
- It turns out to be very easy to get the duration of MP3 files, MPEGs, and other media files on the OS X command line.
- Combining multiple PDF files into a single file
- Automator allows you to combine multiple PDF files into a single file.
- Using Exposé effectively on Mac OS X
- A few simple tricks with window management in OS X can make working with multiple applications or multiple windows much easier and faster.
- Six more pages with the topic Mac OS X tricks, and other related pages
More Taskpaper
- Web display of Taskpaper file
- It is easy to use PHP to convert a Taskpaper task file into simple HTML conducive to styling via CSS.
- Django and Taskpaper
- The Taskpaper format is a simple, structured text format. That means it’s easy to create using Django templates.
