Archive for the ‘programming’ Category
Making a quick email list
February 18th, 2010 at 4:02 pm
I coach my younger son’s YMCA basketball team and use email to send updates and reminders to the other parents. Today my wife needed that list of addresses to coordinate an after-game dinner with the parents of a (friendly) rival team. My first thought was to export the list as a vCard file from my Address Book and email it to her, but importing that into her Address Book would have led to several duplicates and more work for her to weed them out. Also, she had no interest in the phone numbers and other contact information I have for some of these parents; she just wanted the email addresses.
So I went ahead and did the vCard export, and typed up this simple Python filter:
1: #!/usr/bin/python
2:
3: contacts = open('/Users/drang/Desktop/contacts.vcf')
4:
5: for line in contacts:
6: if line[:3] == 'FN:':
7: print line[3:],
8: if line[:6] == 'EMAIL;':
9: colon = line.find(':')
10: print line[colon+1:]
The name and path to the vCard file is in Line 3. I had the vCard file open in TextMate as I wrote the script. The lines with the important data looked like this:
FN:Ms. Laura Ipsum
EMAIL;type=INTERNET;type=HOME;type=pref:lipsum@gmail.com
Lines 5-10 were written with this format in mind. The output was a list of names and addresses
Ms. Laura Ipsum
lipsum@gmail.com
Ms. Dolores Amet
dolores@ametfamily.com
Ms. Elizabeth Consectetur
liz1729@aol.com
which I copied into a email to my wife. Five minutes of effort, maybe, with some interruptions.
I’m sure the script won’t handle every situation, but that’s OK. It was easy to write and it got me what I wanted quickly. I didn’t even save the script. I ran it within TextMate, using the Run Script command (⌘R) in the Python bundle. When I was done, I kept the script in an open window until I wrote this blog post around it.
PNotes
February 11th, 2010 at 10:35 pm
Here are a few miscellaneous paragraphs about my no-server personal wiki system.
I’m tired of calling it “my no-server personal wiki system.” From now on it’ll be called PNotes, which will at least save me some typing. Its GitHub repository will remain the same.
PNotes is missing two things most wikis have: a history of edits and a search field. But it’s easy to overcome both of these limitations.
When I need to create a set of notes for a new project, I copy the PNotes notes folder—my local version of what’s in the GitHub repository—to the new project’s folder and delete the .git subdirectory inside it. I then issue a
git init
command from within notes. This starts up a new git history that will focus not on the programming, which probably won’t change at all, but on the content files. From this point on, I use git add and git commit whenever I think it’s warranted. I’ve thought about putting git commit into the PNotes makefile, forcing a commit whenever I modify or make new HTML pages, but so far I haven’t done so. I prefer the freedom of committing only when I can think up a good commit comment.
Searching hasn’t been as big a deal as I first thought it would be. Normally, I know exactly which note page will have the information I’m looking for, and finding it is simply a matter of scrolling or using the browser’s Find command on that page. For those few occasions when I couldn’t remember where a piece of information is, I just opened a Terminal window in notes and used grep to find what I was looking for. This is not as smooth a solution as having a folder-wide search field available from the browser, but given the rarity of these searches, an in-browser solution just isn’t worth the effort.
One other thing I typically do when I create a new PNotes folder for a project: I replace the generic folder icon with a Moleskine notebook icon like one of these:
![]()
I found one of these, at a larger size, by doing a Google Image search and made the others by fiddling with the band color in Acorn. It’s nice to have the PNotes folder stand out.
A reminder on how to change the icon of a folder:
- Open the image you want to use and copy it to the clipboard.
- In the Finder, do a Get Info on the folder you want to change.
- Select the folder’s icon at the top of the Get Info window by clicking on it.
- Paste. The generic folder icon should be replaced by the image on the clipboard.
This post has turned out to be a bit more miscellaneous than I’d planned.
The no-server notes wiki
February 10th, 2010 at 4:32 pm
I’ve just pushed a new version of my unnamed no-server notes wiki to its GitHub repository. Notes can now be organized in subdirectories instead of all being at the top level. Here’s the README.
This is a no-server personal wiki system that I created to keep track of project notes for work. I’ve put it here because it may be useful to others.

Goals
This is what I want:
- A self-contained file or folder of files that includes everything needed to write and view the notes. I want it to be easy to copy from one computer to another and to archive to DVD. This eliminates most of the available wiki systems, which store everything in a central database.
- The notes themselves to be written in Markdown rather than some specialized wiki markup. I write everything in Markdown and don’t want to shift context when switching from notes to a report. In fact, I’d like to be able to copy directly from my notes—markup included—when writing a report.
- To write the notes in my text editor of choice rather than in an HTML text input box or a word processor. Currently, that editor is TextMate, but TextMate itself isn’t the point. The point is to take advantage of the comfort I feel working in my normal editor. There’s a reason old Unix hackers like to do everything in Emacs or vi; it’s just more efficient to do all your text work in one environment.
- To be able to change the visual style of the notes as my needs or tastes change.
- To create new notes quickly and easily.
Requirements
Apart from what’s in the repository, you’ll need
- Python. The two build scripts,
buildPage.pyandbuildNotesList.py, are written in Python. - GNU make. The build scripts are controlled by a makefile.
- A Markdown processor. I use a self-customized version of Fletcher Penney’s MultiMarkdown. Whatever you use, you’ll have to provide the name of that command on Line 16 of
buildPage.py. - A SmartyPants processor. I use Gruber’s SmartyPants. Again, you’ll have to provide the name of that command on Line 16 of
buildPage.py.
If you need to include mathematical formulas in your notes, you should consider installing Davide Cervone’s jsMath. Once you’ve installed it, you can activate jsMath in the notes by uncommenting Line 10 of the header.tmpl file and adjusting the jsmathpath variable in the project.info file to point to jsMath’s easy.js file.
File structure
The top level of the notes directory contains all the support files, that is, all the files that are distinct from the notes themselves. These files are:
header.tmpl, the HTML template file with all the common code above the content.footer.tmpl, the HTML template file with all the common code below the content.project.info, a file of project-specific data, including the project name and number, the list of contacts (including links to Address Book entries if you’re on a Mac), and thefile://URI for the top-level directory.notes.css, the style file for browsing.notes-print.css, the style file for printing.styleLineNumbers.js, a pair of JavaScript functions that improve the formatting of source code.buildPage.py, a Python script that combines a Markdown input file with the template files and produces a single HTML file.buildNotesList.py, a Python script that searches the directory (and subdirectories) for notes files and generates a list of links to all the notes for display in the sidebar.Makefile, the makefile that controls the build scripts.
Notes files contain the actual content. These files should all have the extension .md and can be in both the top-level directory and in subdirectories. Two sample notes files are included: aa-overview.md in the top-level directory, and testing1.md in the Lab subdirectory.
Creating notes
As mentioned above, notes are just plain text files written in Markdown and saved with an .md extension. The first line will be the note’s title and will appear in the sidebar.

I use ATX-style headers, with hash marks indicating the header level, and I start each file with a first-level header, like this:
# Overview #
The build system is smart enough to get rid of the hash marks when making up the sidebar.
Notes files in subdirectories appear with greater indentation under the name of the directory—like an outline. Within each directory, the notes are ordered alphabetically according to their file names, so you can rearrange the order in which the notes appear in the sidebar by changing the file names without changing their content. At present, there’s no way to change the order of the subdirectories.
Executing make from the top-level directory will generate all the HTML pages, which can be opened with any browser. Subsequent executions of make will generate only those pages whose .md files are new or have been modified. Executing make clean will erase all the HTML files, but will not touch the .md files.
Editing notes
You can, of course, open any .md file in any text editor to make changes. If you’re using TextMate on a Mac, there’s a faster way: click the Edit in TextMate link in the side bar to instantly open the .md file in TextMate—no need to switch to the Finder, open the folder, and double-click the file icon. If you’re a BBEdit user, you can do the same thing, but you’ll probably want to change the name of the link. It’s on Line 33 of header.tmpl.
More details
I wrote a three-part series of blog posts describing this system and its scripts, here, here, and here. The scripts have changed since then, but the basic ideas are the same.
License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License. Do what you want with it, but provide a link back to either my blog posts or to my repository.
CWOB without tweets
February 7th, 2010 at 8:49 am
Looking through my RSS reader this morning, I noticed that Andy Ihnatko has installed a WordPress plugin that collects and summarizes his Twitter stream from the previous day and publishes it as a blog post on the Celestial Waste of Bandwidth.1 Since I
- subscribe to his RSS feed
- follow him on Twitter, and
- don’t feel the need to read everything twice,
I’ve used Yahoo! Pipes to create a customized feed that filters out the Twitter summary posts.

The URL for the feed is at this link.
Regular readers of this blog may be arching their eyebrows. Didn’t Dr. Drang inflict exactly the same sort of redundancies on us last year? Yes, I did, and I’m sorry for it. In my defense, I’ll point out that I
- linked to Pattrick Mosby’s Pipes filter, which filtered out the posts with my tweets;
- later provided my own Pipes filters that did the same thing; and
- eventually dropped the Twitter posts entirely.
I wouldn’t be surprised to see Andy go through the same steps.
Update 2/17/10
I think Andy has turned off the daily Twitter update, but a few days ago a weekly Twitter summary showed up in my RSS reader. I’ve reworked the above-linked Yahoo! Pipes filter to get rid of those, too. The screen shot shows the current filter.
-
Ah, I remember when it was just a Colossal Waste of Bandwidth. ↩
More Avery labels
February 4th, 2010 at 4:02 pm
This week I had to create lots of small labels to attach to laboratory samples. To make this easier, I modified my file folder label script to handle the smaller Avery 5167 labels, the kind usually thought of as return address labels.
The new program, called ptlabels (“print tiny labels”), follows the same logic as the old one and uses the same command-line options. You can tell it which row and column to start on through the -r and -c options. The input format is also the same:
- Individual labels are separated by a blank line.
- Header lines, which get printed in bold, are designated by a leading hash mark.
- Header lines can have a left-justified and right-justified part; they’re separated by a vertical bar.
- Headers apply to all subsequent labels until a new header line is encountered.
As an example, this input
#Lorem project|1234
Sample 1
Sample 2
Sample 3
Sample 4
Sample 5
Sample 6
Sample 7
Sample 8
#Dolor project|9876
Sample 1
Sample 2
Sample 3
Sample 4
passed to
ptlist -r 3 -c 2
generates this output

As with the file folder label script, I find it easiest to run the script in TextMate via Filter Through Command… (⌥⌘R).

The script is in Perl, because that was my main language back when I wrote the original version. Rewriting in from scratch in Python would have been a waste of time.
1: #!/usr/bin/perl
2:
3: use Getopt::Std;
4:
5: # Usage/help message.
6: $usage = <<USAGE;
7: Usage: ptlabels [options] [filename]
8: Print tiny labels on Avery 5167 sheets
9:
10: -r m : start at row m (range: 1..20; default: 1)
11: -c n : start at column n (range 1..4; default: 1)
12: -h : print this message
13:
14: If no filename is given, use STDIN. A label entry is a plain text
15: series of non-blank lines. Blank lines separate entries.
16:
17: The first line of an entry is special. If it starts with a #, then it's
18: considered a header line. Everything in the header line up to the | is
19: printed flush left in bold and everything after the | is printed flush
20: right in bold. Subsequent lines are printed centered in normal weight.
21: If the first line of an entry doesn't start with #, it uses the header
22: of the previous entry.
23: USAGE
24:
25: # Set up geometry constants for Avery 5167.
26: $topmargin = 0.55;
27: $pocol[1] = 0.45;
28: $pocol[2] = 2.50;
29: $pocol[3] = 4.55;
30: $pocol[4] = 6.60;
31: $lheight = 0.50;
32:
33: # get starting point from command line if present
34: getopts('hr:c:', \%opt);
35: die $usage if ($opt{h});
36:
37: $row = int($opt{r}) || 1; # chop off any fractional parts and
38: $col = int($opt{c}) || 1;
39:
40: # Bail out if position options are out of bounds
41: die $usage unless (($row >= 1 and $row <= 20) and
42: ($col >= 1 and $col <= 4));
43:
44: # Set initial horizontal and vertical positions.
45: $po = $pocol[$col];
46: $sp = ($topmargin + ($row - 1)*$lheight);
47:
48: # Pipe output through groff to printer (manual feed).
49: open OUT, "| groff | lpr -o ManualFeed=True";
50: # Change to PDF before sending to printer.
51: # open OUT, "| groff | ps2pdf - - | lpr -o ManualFeed=True";
52: # Preview output instead of printing directly.
53: # open OUT, "| groff | ps2pdf - - | open -a /Applications/Preview.app";
54: # Print raw troff code for debugging.
55: # open OUT, "> labels.rf";
56: select OUT;
57:
58: # Set up document.
59: print <<SETUP;
60: .vs 12
61: .nf
62: .ll 1.50i
63: .ta 1.50iR
64:
65: SETUP
66:
67: # The troff code for formatting a single entry, with placeholders for
68: # positioning on the page. The magic numbers embedded in the formatting
69: # commands make the layout look nice.
70: $label = <<ENTRY;
71: .sp |%.2fi
72: .po %.2fi
73: .ps 10
74: .ft HB
75: %s
76: .ps 10
77: .ft H
78: .ce 2
79: %s
80: .ce 0
81: ENTRY
82:
83: # Slurp all the input into an array of entries.
84: $/ = "";
85: @entries = <>;
86:
87: $bp = 0; # we don't want to start with a page break
88:
89: foreach $body (@entries) {
90: # Parse and transform the header and body.
91: if ($body =~ /^#/) { # it's a header line
92: ($header, $body) = split(/\n/, $body, 2);
93: $header = substr($header, 1);
94: $header =~ s/\|/\t/;
95: }
96: $body =~ s/\s+$//;
97:
98: # Break page if we ran off the end.
99: if ($bp) {
100: print "\n.bp\n"; # issue the page break command
101: $bp = 0; # reset flag
102: }
103:
104: # Print the label.
105: printf $label, $sp, $po, $header, $body;
106:
107: # Now we set up for the next entry.
108: $col = ($col % 4) + 1; # step to next column
109: $po = $pocol[$col];
110: if ($col == 1) { # we just went down a row
111: $row++;
112: if ($row > 20) { # we just went off the bottom
113: $bp = 1; # start a new page
114: $row = 1; # at the top
115: }
116: $sp = ($topmargin + ($row - 1)*$lheight);
117: }
118: }
The geometry constants in Lines 26-31 were initially set by making measurements of the labels and then adjusted through trial and error until the printing was nicely aligned with the die cuts on the label sheets. The final values are based not only on the sheet geometry, but also on how the labels pass through my printer via the manual feed slot. For good alignment on another printer, the values might need adjusting by a few hundredths.
Line 49 was also written with my default printer in mind. Because it’s a PostScript printer, I can take the PostScript output directly from groff and pipe it to lpr—no need to convert it first to PDF and no need to use lpr’s -P option to tell it which printer to use. (The -o option should be self-explanatory.)
Line 51 (commented out) is an example of what you may need to do if you don’t have a PostScript printer.
51: # open OUT, "| groff | ps2pdf - - | lpr -o ManualFeed=True";
Ps2pdf is part of Ghostscript, an open source suite of PostScript utilities that doesn’t come with OS X, but which I find invaluable. The two hyphens after ps2pdf tell it to use standard input and output instead of files on disk.
A more Mac-like possibility is shown in Line 53:
53: # open OUT, "| groff | ps2pdf - - | open -a /Applications/Preview.app";
This generates the PDF and opens it in Preview so you can see it before printing. I’m a wild and impetuous sort of guy, so I just send it off the printer and let the ink fall where it may.
Misty water colored memories
January 30th, 2010 at 4:12 pm
Among the many disadvantages of middle age are: the loss of suppleness in both your mind and body; the simultaneous loss of hair where you want it and growth where you don’t; and the recognition that people in Cialis commercials are meant to represent you (albeit much better looking). One of the few advantages is the pleasure you get from complaining about how the world is going to hell in a handbasket and how much better things were in your day.1 I’m sorry to say that an unfortunate side effect of this week’s iPad announcement is that pre-middle-agers are now horning in on nostalgia, a pastime that should be restricted to their elders.
For example, both Mark Pilgrim (37) and Alex Payne (26!) have written little essays on how the iPad is going to destroy the idyllic world in which they grew up and blossomed, replacing it with a harsh dystopia in which turtlenecked priests in Cupertino decide who may learn to program and who may not. The essays have struck a chord with other wet-behind-the-ears programmers who are worried that the rise of appliance computers will push out the kind of open, tinkerable computers they grew up with.
Maybe they’re worried because they’re so young they’ve never seen change before. I have no doubt that iPad-like devices will change the way computing is done, and I have no doubt that this will make the practice of programming very different 10-15 years from now. But it doesn’t worry me, because I’m old enough to have seen changes at least as drastic.
When I took my first programming class— Well, let’s stop right there. When I started programming, almost everyone learned to program by taking a college-level class. This was the late 70s, and although the personal computer revolution was under way, PCs were by no means common.
The first order of business in my introductory programming course was learning how to use a keypunch machine. That’s how we made the stacks of cards fed into the computer. We almost never saw the computer itself. Computer operators—talk about a priesthood!—would come out of the machine room, pick up the stacks of cards, and do God knows what to them. Some time later (often hours later), the cards would be returned to us along with a printout of the results, which were usually a set of compiler errors.
A year or two later, when I first sat down to work at an interactive terminal, it was an absolute revelation. I could correct my typing errors by backspacing!
The march of computing history has been toward greater accessibility. More computers, more people using computers, and more people able to program their computers. I don’t see this changing.
The nature of programming will definitely change, just as it has in the past. My first computer programs were compiled, and hardcore programmers wrote in assembly language. Nowadays it’s more common for people write in interpreted (or perhaps semi-compiled) languages. No one seriously considers this to be a sign of the death or programming.
I was particularly struck by one part of Mark Pilgrim’s essay. He talks about starting in BASIC on an Apple ][e and then moving on to a Mac, where he played with MacsBug and ResEdit. The thing is, in 1984 much of what is now being said about the iPad was being said about the Mac. You couldn’t write programs on the first Macs, development was done on a Lisa. It wasn’t until HyperCard that the Mac had a simple, free, Apple-supported development environment that kids could play around with.
I’m not predicting a native development environment for the iPad, but I wouldn’t be surprised to see Apple loosen its restrictions as time goes on. And in the meantime, the iPad will come with a JavaScript interpreter, which clever people will be able to use for some elementary scripting. And Apple will be violating the letter of its own “no interpreters” policy when it ships Numbers. I’m not saying spreadsheets are the best way to learn programming, but then again, neither was BASIC.
So buck up, Gen Xers and Gen Yers and whatever other Gens there are! Things won’t be as bad as you fear.
And get off my lawn.
-
This does not, of course, prevent you from also lecturing the young on how tough the world used to be and how easy they have it. Memory loss allows a certain inconsistency. ↩
My script hall of fame
January 27th, 2010 at 1:25 pm
Many of my posts here have been about the writing—or rewriting or rerewriting—of scripts to automate the dull, repetitive, clicky-click tasks so common to computer use. While almost all of these scripts have been worthwhile, a few have proved so useful that I use them on a weekly or even daily basis. These are the member of my personal scripting hall of fame.
Folder labels
I like the project file folders in my office to have crisp laser-printed labels. There are plenty of templates out there for Avery labels and their clones, but they’re usually made for MS Word or some other program I don’t use. Also, there’s a lot of repetitive typing associated with those templates, and I obviously want to avoid that. So I wrote a script called pflabels that takes plain text input in a simple format and generates output for printing on a sheet of 1″×4″ labels (Avery 5261 or the equivalent).

The input looks like this:
#Kernighan Building|4215
Drawings
Contract
Correspondence
Photographs and
videotape
#Ossanna Residence|4332
Report
Correspondence
The headings, which have the project name and number separated by the pipe character (|), are denoted with an initial hash symbol (#), and individual labels are separated by blank lines. If I’m going to make several labels for the same project (which is usually the case), I need only enter the heading once. The script takes two options, -r and -c, which tell it which row and column to start on, so it can print on label sheets that have been partially used.
I generally type up my label input in TextMate and then run pflabels on that input via the Text>Filter Through Command… (⌥⌘R) command.
Screenshot uploader
This script, called snapftp:
- Takes a snapshot of some portion of my computer screen.
- Names it.
- (Optionally) resizes it.
- (Optionally) uploads it to my blog.
- Puts the URL of the uploaded image on the clipboard for pasting into a post.
I’ve configured FastScripts to run snapftp with the ⌃⌥⌘4 key combination, a minor variation on the Apple-standard ⌘⇧4 key combo.

There are certainly commercial products that do some or all of these things, but none are so perfectly tuned to my way of working. I can’t imagine going back to writing posts like this without it.
Markdown links in TextMate
I write almost everything in Markdown, mainly because I can forget about the formatting and just type, but also because it’s so easy to read. To keep the visual clutter to an absolute minimum, I use reference-style links, which puts all the URLs at the bottom of the document, out of the flow of the text.

I use three TextMate command/snippet/macros to do this:
- One for inserting links as I type, triggered by ⌃L.
- One for inserting links after I’ve already typed out the text, triggered by ⌃⌥L.
- One for inserting Google’s I Feel Lucky link on text already typed, triggered by ⌃⌥⇧L.
The first two are described here, and the third is described here. They’re a bit complicated to set up but are wonderfully simple to use. I should probably turn them into a Bundle for easier installation.
URL getters for TextExpander
This started out as a set of scripts for getting the URL (or a shortened version of the URL) of the page showing on the visible tab of the frontmost Safari window, and the scripts were triggered by key combinations defined in FastScripts. Then, after seeing this tip by Jeff Gamet, I turned them into a set of TypeIt4Me snippets. When I switched from TypeIt4Me to TextExpander, I moved the snippet over and that’s what I use today.
The two workhorses are:
- The snippet triggered by
;furl, which gets the aforementioned URL and inserts it. - The snippet triggered by
;surl, which gets the URL, shortens it through the Metamark shortening service (run by perl.org), and inserts it.
I tend to use the first when writing posts like this or email and the second when using links on Twitter. The great advantage is that I can add a link to a page I’ve been reading without having to switch back to Safari to get it.
More recently, I added a few more snippets for getting the URLs of the first, second, third, and fourth Safari tabs, regardless of whether they are frontmost.
BBC Radio recording scripts for Audio Hijack Pro
These scripts, written in Python and AppleScript, differ from those described above in that I never actually run these scripts myself. They’re run automatically on a schedule set in Audio Hijack Pro, and they record and tag certain BBC Radio 2 shows and put them into my iTunes library for syncing with my iPod. In effect, they turn shows that aren’t podcasts into podcasts for me.
The scripts are described here and they’re also available in this GitHub repository.
Library loan tracking
This script, like the set of BBC scripts, is run automatically—in this case, by a launchd process. Every morning, it logs in to my local library and gathers information on all the items my family has checked out or on hold. It then sends that information to my wife and me in a nicely formatted email.

Now it’s true that my library emails us a notice shortly before an item is due, but the advantage of this system is that we see everything at once and can gather up all the books that will be due in the next several days before going to the library to make a return. And we don’t have to remember to sign on to the library’s web site; the information is delivered to us every day.
Suspend and sleep screen
This is a pretty recent script, but I’ve come to love it. Without logging me out, it suspends my user session and puts the display to sleep. Seeing the Desktop swing around in that cube animation (which I’ve been a fan of since Andy Hertzfeld used a simplified version of it in Switcher) has become the visual signal that my day at work is over.
Exploring the Simplenote API
January 20th, 2010 at 4:25 pm
I’ve been meaning to work with the Simplenote API ever since it was announced, thinking it would be a good way to keep my plain-text todo lists1 synced between my computers and my iPhone. I haven’t done any syncing yet, but I have written a utility script that will get me started.
There are, as you may know, already several ways to sync your Simplenotes. Most of them, unfortunately, are tied to special note-taking apps that I don’t want install. One, Fletcher Penney’s SimplenoteSync, is more general, but works by syncing all the notes to a set of files in a single directory on your local computer. I’m looking for something a little more fine-grained than that—a way of syncing individual notes to individual files that can be anywhere on my computer.
As a first step, I wrote the following script, simplenote-index, which gathers and prints out information for all the notes on the Simplenote server.
1: #!/usr/bin/python
2:
3: from urllib import urlopen # standard Python library
4: from base64 import b64encode # standard Python library
5: import simplejson # http://code.google.com/p/simplejson/
6:
7: # Login credentials.
8: email = 'someone@example.com'
9: password = 'seekret'
10:
11: # Get my authorization token for later calls.
12: loginURL = 'https://simple-note.appspot.com/api/login'
13: creds = b64encode('email=%s&password=%s' % (email, password))
14: login = urlopen(loginURL, creds)
15: token = login.readline().rstrip()
16: login.close()
17:
18: # Get the note index.
19: indexURL = 'https://simple-note.appspot.com/api/index?auth=%s&email=%s' % (token, email)
20: index = urlopen(indexURL)
21: noteList = simplejson.load(index)
22:
23: # Print the first line of each note along with its key.
24: baseURL = 'https://simple-note.appspot.com/api/note?key=%s&auth=%s&email=%s'
25: for i in noteList:
26: noteURL = baseURL % (i['key'], token, email)
27: title = urlopen(noteURL).readline().decode('utf-8').rstrip()[:40]
28: print '''Title: %s
29: Key: %s
30: Modified: %s
31: Deleted: %s
32: ''' % (title, i['key'], i['modify'], i['deleted'])
I think the comments explain it pretty well; there’s not much to it. It logs in, gets an authorization token, then collects the information on each of your notes on the server. Here’s the sort of output to expect:
Title: Hardware store
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRiF5BsM
Modified: 2009-09-08 00:24:13
Deleted: False
Title: Metra Eastbound Mon-Fri
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRij5h4M
Modified: 2010-01-01 17:51:59
Deleted: False
Title: Metra Eastbound Saturday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRjC3h4M
Modified: 2010-01-01 17:52:33
Deleted: False
Title: Metra Eastbound Sunday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRi35h4M
Modified: 2010-01-01 17:52:46
Deleted: False
Title: Metra Westbound Mon-Fri
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRik5h4M
Modified: 2010-01-01 17:53:05
Deleted: False
Title: Metra Westbound Saturday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRjL3h4M
Modified: 2010-01-01 17:53:20
Deleted: False
Title: Metra Westbound Sunday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRjT3h4M
Modified: 2010-01-01 17:53:37
Deleted: False
Title: Swimming City Times 2009
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRiG5BsM
Modified: 2010-01-01 17:54:33
Deleted: False
Title: Swimming Meet Event Order
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRiH5BsM
Modified: 2010-01-01 17:54:59
Deleted: False
Title: Weight
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRiTii8M
Modified: 2010-01-20 12:35:52.611425
Deleted: False
Like Simplenote itself, the script treats the first line of each note as its title (the script prints only the first 40 characters of the title so the formatting doesn’t get screwed up). The important thing for the work I intend to do later are the keys. These are character strings that uniquely identify each note and are essential for scripts that read and write notes. The goal of simplenote-index is to give me those keys so I can hard-wire them into my syncing scripts.
With lots of notes, simplenote-index will give lots of output. Grep is a great way to filter the output down to a reasonable level. For example,
simplenote-index | grep -i -A 3 metra
will give me just the notes with the local train schedule
Title: Metra Eastbound Mon-Fri
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRij5h4M
Modified: 2010-01-01 17:51:59
Deleted: False
--
Title: Metra Eastbound Saturday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRjC3h4M
Modified: 2010-01-01 17:52:33
Deleted: False
--
Title: Metra Eastbound Sunday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRi35h4M
Modified: 2010-01-01 17:52:46
Deleted: False
--
Title: Metra Westbound Mon-Fri
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRik5h4M
Modified: 2010-01-01 17:53:05
Deleted: False
--
Title: Metra Westbound Saturday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRjL3h4M
Modified: 2010-01-01 17:53:20
Deleted: False
--
Title: Metra Westbound Sunday
Key: agtzaW1wbGUtbm90ZXIMCxIETm90ZRjT3h4M
Modified: 2010-01-01 17:53:37
Deleted: False
The -i option to grep makes the search case-insensitive, and the -A 3 option prints not only the line containing the search string, but the three lines after it as well.
With this easy one under my belt, I can start working on the more complicated syncing scripts.
-
No, I don’t use OmniFocus anymore. It was just too much work for the good I got out of it. I’m back to my TextMate-based LGTD system, which I’ve updated a bit and really should do a short post on. ↩
An odd coincidence
January 15th, 2010 at 7:59 pm
Less than 24 hours after my last post, in which I said I wanted to explore build systems other than make to generate my serverless wiki project notes files, Allan Odgaard writes a post on make that leads me to think I shouldn’t be too hasty in abandoning a software tool that’s stood the test of time. Allan is a smart guy who’s written some great stuff and sounds very authoritative when he says computer sciencey things like “directed acyclic graph.” Also, the last example in his post is a frighteningly close match to what I’m doing, so I think I’ll listen to him.
He says this post is the first of two on the topic of make. I look forward to Post 2 almost as much as I do to TextMate 2. Hope I don’t have to wait as long.
HTML notes
January 14th, 2010 at 11:12 pm
Every once in a while, I spend a little time Googling to see if someone has made a personal wiki system—or any wiki system, really—that will work better for my project notes than the home-grown system I developed a couple of years ago. When I took one of those trips around the internet last week, I returned, as always, empty handed and with a growing sense that I was never going to find what I was looking for. So I’ve decided to put a little effort into my existing system and make it easier to use.

I wrote about this note-taking system, a serverless wiki, in a series of three posts back in 2008. The first of those posts described what I wanted out of the system, and the latter two posts went into how I use it and some details of the programming. At the risk of being repetitive, this is what I want in a personal wiki:
- A self-contained file or folder of files that includes everything needed to write and view the notes. I want it to be easy to copy from one computer to another and to archive to DVD.
- The notes themselves to be written in Markdown. I write everything in Markdown and don’t want to change.
- To write my notes in my text editor of choice. Currently, that editor is TextMate, but TextMate itself isn’t the point. The point is to take advantage of the comfort I feel working in my normal editor.
- To be able to change the visual style of the notes as my needs or tastes change.
- To create new notes quickly and easily.
Were it not for Items 2 and 3, I’d be using VoodooPad. Were it not for Items 3 and 4 (and a small incompatibility with Safari), I’d be using TiddlyWiki or one of its offshoots. But I’m not interested in compromising on these things, so it looks like I’ll be sticking with my self-made system. Which works, but could use some polish and a new feature or two.
To that end, I did a little code cleanup, put it under revision control, and set up a repository for it on GitHub in anticipation of making some improvements over the next few weeks. I want to:
- Add a hierarchical structure to the notes so they can be categorized within a project. A flat structure is fine for many projects, but I’ve found that the notes for bigger projects start getting cluttered and hard to manage without the ability to gather notes into subfolders.
- Create a TextMate bundle to automate common actions, like making a new note from an internal link. This may need to be in a separate repository.
In addition, I may change the build system that drives the conversion of notes from Markdown (for writing) to HTML. Currently, I’m using make, which has the advantage of ubiquity, but which also has a clumsy syntax that I’ve never felt confident in using. I know there are several alternatives, but I don’t know enough about them yet to choose among them.
I probably won’t write any more about it until I think these improvements are complete, but you can follow the repository if you want to track my progress.





