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.
- Fraise: Jean-François Moy and Peter Borg
- Fraise is the successor to the great text editor Smultron. It’s an easy-to-use, powerful, free, text editor with tabs, split windows, syntax coloring, and more.
More macOS tricks
- 42 Astoundingly Useful Scripts and Automations for the Macintosh
- MacOS uses Perl, Python, AppleScript, and Automator and you can write scripts in all of these. Build a talking alarm. Roll dice. Preflight your social media comments. Play music and create ASCII art. Get your retro on and bring your Macintosh into the world of tomorrow with 42 Astoundingly Useful Scripts and Automations for the Macintosh!
- Save clipboard text to the current folder
- Use the Finder toolbar to save text on the current clipboard directly to a file in the folder that Finder window is displaying.
- Avoiding lockFocus when drawing images in Swift on macOS
- Apple’s recommendation is to avoid lockFocus if you’re not creating images directly for the screen. Here are some examples from my own Swift scripts. You can use this to draw text into an image, and to resize images.
- What app keeps stealing focus?
- I’ve been having a problem on Mac OS X with something stealing focus. Here’s how to at least find out what that something is.
- Enable AirPrint for all connected Mac printers
- I have an iPad and an old workhorse of a printer, an HP 1012 LaserJet, connected to my iMac. I almost never need to print from the iPad, but when I do, handyPrint works.
- 14 more pages with the topic macOS tricks, and other related pages
More Perl
- Simple .ics iCalendar file creator
- A simple Perl script to create an ics file from a human-readable text of events.
- No premature optimization
- Don’t optimize code before it needs optimization or you’re likely to create unoptimized code.
- Using Term::ANSIColor with GeekTool
- Rather than using the raw codes directly, Perl (at least on OS X) comes with Term::ANSIColor built in.
- 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.
- Three more pages with the topic Perl, and other related pages
More TaskPaper
- GeekTool, TaskPaper, and XML
- A script to convert a TaskPaper file to XML so as to filter it for specific tags and display the results on the Desktop.
- 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.