Author Archive
Yojimbo 1.5 Script Compatibility
Today Bare Bones Software released Yojimbo 1.5, a significant update to the all-purpose desktop database. Since I’ve written quite a few little scripts for the program, I gave them each a quick test to check whether they worked with Yojimbo 1.5 and Mac OS X 10.4.11. Happily, most of them do.
Compatible
- Bookmark in Yojimbo
- Tag List
- Import Note Service
- Export with Comment Tags
- Archive Bookmarks
- Backdate Items
- Backdate Import
Updated
- Expanded Comment Fields I’ve posted a new set of
nibfiles compatible with Yojimbo 1.5.
I haven’t tried the indispensable widescreen hack yet.
Posted on Wednesday, December 5th, 2007. Tags: mac, yojimbo.
Pdftk 1.41 for Intel Macs
Pdftk is a useful utility for manipulating PDF files. A Macintosh binary of the current version was not available, except perhaps from Fink or Darwin Ports, so I built it myself. My version is not universal, but it doesn’t require a package manager, either.
Until such time as this binary is available directly from the official pdftk site, you can get it here:
Download pdftk 1.41 for Intel Macs 1MB
Note: the default pdftk Makefile settings result in a binary that still relies on gcj. Until such time as this issue is resolved, the binary probably won’t be much use!
Building pdftk requires gcj, which comes with gcc, but apparently not with Mac OS X. So, I downloaded and built GCC 4.2.2. Why 4.2.2? Because it was the most recent version.
./configure --prefix=/usr/local/gcc/4.2.2 --disable-multilib
make
make install
The --prefix option installs everything out of the way in its own little directory; I wasn’t really interested in upgrading to a new version of gcc just to build pdftk. The --disable-multilib option turns off some crap that caused build errors.
Once that’s done, building pdftk is just a matter of pointing the makefile at the new gcc stuff.
cd pdftk
# In Makefile.MacOSX, define TOOLPATH=/usr/local/gcc/4.2.2/bin/
make -f Makefile.MacOSX
make install
So that’s how you roll your own.
Posted on Monday, November 26th, 2007. Tags: mac, pdf, tcl.
strpdf
strpdf creates single-page PDF files populated with one-line text strings. The page size and string placement are configured with command line options. It is a purposely simple tool.
Download
Installation instructions and other notes are included with the downloads.
- strpdf-1.0-mac.zip (1.9M) Requires Mac OS X 10.4; untested on Mac OS X 10.5.
- strpdf-1.0-win.zip (640K) Untested, but might work at the Windows command prompt.
- strpdf-1.0-kit.zip (95K) Requires a Tclkit for your platform (8.4.16 recommended).
Usage
Strings are placed on the page with the -text option. General configuration options must be given before the first -text option. PDF data is printed to stdout, so redirection should be used to capture the result.
Here is a simple example:
strpdf -text 'Hello, world!' center middle > helloworld.pdf
The -text option has three parameters. The first is the string to print. The second and third specify the horizontal and vertical locations of the string on the page, respectively. Valid horizontal positions are left, center, and right. Valid vertical positions are top, middle, and bottom. The left, right, top, and bottom positions must each be followed by an additional parameter which specifies the distance from the indicated edge of the page to the closest side of the string.
Multiple instances of the -text option can be used to place multiple strings on the page:
strpdf -text 'Upper right' right 0.5 top 0.5 -text 'Lower left' left 0.5 bottom 0.5 > corners.pdf
The default page size is 8.5 × 11 inches (letter). The -paper option understands a few other common paper sizes, which can be listed with strpdf paper:
strpdf -paper a4 -text 'A4 FTW' center top 1 > a4.pdf
Alternatively, arbitrary page dimensions can be specified with the -width and -height options:
strpdf -width 5 -height 5 -text 'Square' center middle > square.pdf
By default, page dimensions and string position parameters are interpreted as inches. The -units option allows these values to be given in millimeters or points. The supported -units parameters are mm, pt, and in.
The -orient option provides a landscape mode that swaps the width and height of the page. This can be done manually with the -width and -height options, but the landscape option is convenient for use with preset paper sizes:
strpdf -paper legal -orient landscape -text 'Legal fine print' center bottom 0.5 > landscape.pdf
The default font is 12-point Helvetica. The -size option sets the font size (in points) and the -font option sets the font face. If given before the first -text string, these options set the default font. Given after the parameters of a particular -text option, they modify only that string:
strpdf -font Times-Roman -size 18 -text 'One' left 1 top 1 -text 'Two' center top 1 -size 24 -font Courier -text 'Three' right 1 top 1 > fonts.pdf
Valid font faces can be listed with strpdf font. Valid fonts are not necessarily available on your computer, nor are the fonts on your computer necessarily compatible with strpdf.
There is a -compress option which will compress the PDF data if given the
parameter 1, but in most cases it yields little benefit. For small files such
as the examples on this page, compression may actually result in slightly larger files.
Applications
I use strpdf in conjunction with pdftk to “stamp” otherwise static PDF documents with bits of variable text. Because these are both free command line utilities, the process is easily automated and requires no commercial software. Here a registration string is stamped on each page of a report:
strpdf -text 'Registered to John Doe' center top 0.25 > registration.pdf pdftk document.pdf stamp registration.pdf output registered-document.pdf
Alternatively, strpdf’s output can be piped directly to pdftk:
strpdf -text 'Registered to John Doe' center top 0.25 | pdftk document.pdf stamp - output registered-document.pdf
Posted on Monday, November 26th, 2007. Tags: mac, pdf, tcl.
iTunes Library Item Transfer
My laptop has a 60 GB hard drive. I have a 500 GB external drive which houses my iTunes library and other media. I like to keep some iTunes content on my laptop, but using the Finder or the “Add to Library” file browser to move particular things between libraries gets tedious.
So, I wrote a script that makes it a little simpler. Now I can use iTunes itself to select the items to transfer instead of browsing for the actual files to pull into the target library. Might not sound like a big difference, but it seems like less fuss to me.
Here’s how it works.
Download the script (5k) and put it in ~/Library/Scripts/Applications/iTunes.
Select some items in iTunes and run the script. iTunes will quit and you will be prompted to reopen it with a different library:

Hold down the Option key as iTunes starts up to select a different library. If you’re transferring files to a new library for the first time, you could even create the new library at this point.

Once you have finished choosing a library, return to the prompt and click Transfer. The items you previously selected will be transferred to the current library and shown in a new “Transfer” playlist labeled with the current date and time.
Tested with Mac OS X 10.4.11 and iTunes 7.5 with the “Copy files to iTunes Music folder when adding to library” option enabled under Advanced→General preferences.
I reckon this could be done with iPhoto, too.
Posted on Thursday, November 15th, 2007. Tags: applescript, itunes, mac.
Chipmunk Basic Language Module
I’ve updated my Chipmunk Basic language module for TextWrangler/BBEdit. Named subroutines are now identified in the function popup menu.

Download cbastw.plist.zip 2k (requires TextWrangler 2.2 or BBEdit 8.5)
Posted on Monday, November 12th, 2007. Tags: code.
LDraw Part Search Services
Just some handy reference tools for the discerning LDraw hobbyist. Quickly access information about selected parts from any application.
Download LDraw Part Search Services 127k
Four popular databases are currently supported: Bricklink, the LDraw Parts Tracker, Lugnet Partsref, and Peeron.
Posted on Thursday, November 8th, 2007. Tags: LEGO.
Lselect Toolbar Icon
Henrik Nyh has created a great Leopard-themed toolbar icon for lselect. Read his post for more information about using lselect and other useful scripts as Finder toolbar buttons with custom icons.
For your convenience, I’ve prepared a copy of the script as a tiny application ready to drag to your toolbar:
Download lselect toolbar app 15k
This is a fine time to mention that lselect really is quite useful! Use it to quickly select all the files in a folder that match a simple pattern.
Posted on Tuesday, November 6th, 2007. Tags: applescript, finder, mac.
Get In on the Ground Floor
I’ve posted a few drawings recently. Here are the new ones, and here are a few of my favorites:
Originals available for $1000 each. An additional $100 materials fee applies to limited edition grocery bag sketches. Free shipping if you order by December 1. Cash and PayPal accepted; sorry, no personal checks.
Posted on Monday, October 29th, 2007. Tags: art.
Instruction Step Fading with PreL3P
By substituting different colors in different parts of a model, PreL3P can be used to create interesting effects such as the step-by-step highlighting seen here:
This page explains how this image was created. It is intended as a demonstration of what can be done with PreL3P, but other relevant topics are discussed. Windows users may be interested in LPub as a more convenient solution.
Color Preparation
Two sets of color code definitions are needed to achieve this effect. A set of modified colors is used first to give parts from previous steps a faded appearance. Then a set of normal colors is loaded to give new parts their vivid hue.
Here are the normal colors from ldconfig.ldr used to draw the current step and the final image:
0 normal.ldr
0 !COLOUR Green CODE 2 VALUE #008C14 EDGE 0
0 !COLOUR Red CODE 4 VALUE #C40026 EDGE 0
0 !COLOUR Yellow CODE 14 VALUE #FFDC00 EDGE 0
I used Hex Color Picker along with the standard HSB saturation slider to choose faded versions of these colors. You can use the color picker from any application to do this.
Of course, this approach is not practical for converting large numbers of colors. You’ll have to devise your own system for selecting and generating suitable substitute colors.
Here are the faded colors used for parts from previous steps:
0 faded.ldr
0 !COLOUR Green CODE 2 VALUE #598952 EDGE 0
0 !COLOUR Red CODE 4 VALUE #B26676 EDGE 0
0 !COLOUR Yellow CODE 14 VALUE #FBEC87 EDGE 0
Steps
The STEP meta command marks the end of each instruction step in an LDraw model. For example, here are the first three steps of the doghouse model pictured above:
1 2 0 0 0 1 0 0 0 1 0 0 0 1 41539.dat
0 STEP
1 14 50 -24 30 -1 0 0 0 1 0 0 0 -1 3005.dat
1 14 50 -24 -30 -1 0 0 0 1 0 0 0 -1 3005.dat
1 14 -50 -24 0 0 0 -1 0 1 0 1 0 0 3010.dat
0 STEP
1 14 0 -24 50 1 0 0 0 1 0 0 0 1 3009.dat
1 14 0 -24 -50 1 0 0 0 1 0 0 0 1 3009.dat
0 STEP
Most LDraw editors make it easy to create and organize steps. For instance, steps are always shown as part of the model hierarchy in Bricksmith’s “File Contents” drawer:

Once a model is complete, its constituent steps can be exported as a series of individual files that represent the model up to that point. In other words, each exported step model is essentially identical to the original model except that it is truncated after the corresponding step.
Rendering each of these partial models produces an image depicting each step in the instructions.
PreL3P Meta Commands
Before proceeding to render the step models, PreL3P meta commands are inserted at the beginning of the file and at the beginning of the most recent step to invoke the appropriate color substitution schemes. The -ldconfig option is used to load the faded.ldr and normal.ldr files prepared above. (PreL3P supports the notion of “LDraw configuration files”—files containing pertinent meta commands; if present, any visible linetypes are ignored.)
By default, PreL3P does not modify the basic color codes understood by L3P. To accomplish step fading, however, it may be necessary to do so. The +codes option tells PreL3P which color codes should be kept in their original form. The special parameter none causes all codes to be converted.
Here is the third step model with meta commands inserted:
0 !PREL3P +codes none
0 !PREL3P -ldconfig faded.ldr
1 2 0 0 0 1 0 0 0 1 0 0 0 1 41539.dat
0 STEP
1 14 50 -24 30 -1 0 0 0 1 0 0 0 -1 3005.dat
1 14 50 -24 -30 -1 0 0 0 1 0 0 0 -1 3005.dat
1 14 -50 -24 0 0 0 -1 0 1 0 1 0 0 3010.dat
0 STEP
0 !PREL3P -ldconfig normal.ldr
1 14 0 -24 50 1 0 0 0 1 0 0 0 1 3009.dat
1 14 0 -24 -50 1 0 0 0 1 0 0 0 1 3009.dat
For each successive step the -ldconfig normal.ldr line should be inserted later in the file. If your editor includes the STEP lines in exported step models, it is fairly easy to locate the beginning of the last step. The correct location can also be found by comparing each step model file to the previous step’s file; the new step starts where the files differ. This is the method used by Travis Cobbs’ shell script.
The first step is a special case since there are no previous steps that need to be faded. You may be able to render it without modification. For consistency, however, you could load the standard color set at the beginning of the file:
0 !PREL3P +codes none
0 !PREL3P -ldconfig normal.ldr
1 2 0 0 0 1 0 0 0 1 0 0 0 1 41539.dat
Note that the preparations are slightly more complex for MPD files. Another -ldconfig faded.ldr command would be needed at the end of the main model to draw submodels from previous steps in the faded colors. Any submodels included in the current step would need to use normal.ldr again. Submodels referenced by the previous step and the current step present a challenge that is left as an exercise for the reader.
Running PreL3P
Once the meta commands have been inserted, the step models can be processed with PreL3P. This replaces the original color codes with hexadecimal values that represent the exact shades defined in the color configuration files.
prel3p -in doghouse3.ldr -out doghouse3-faded.ldr
Rendering
Finally the faded step models are ready to be rendered. PreL3P’s name is a bit of a misnomer; the output works just as well with LDView (note, however, that these hexadecimal colors do not conform to the LDraw format specification, so don’t expect them to work with all LDraw software).
Currently, it is easiest to render a batch of images from the command line. If you save a bunch of command lines to a file named render, you can run them all with sh render (other automation methods may be forthcoming). Here’s what one command looks like:
ldview doghouse3.ldr -SaveSnapshot=doghouse03.png -AutoCrop=0 -SaveZoomToFit=0 -WindowWidth=1024 -WindowHeight=1024 -SaveActualSize=1 -cg30,45 -ModelCenter=0.0,-50,0.0 -ModelSize=250
With LDView 3.2 on Mac OS X, you might need to expand ldview to /Applications/LDView/LDView.App/Contents/MacOS/LDView. Only the first two arguments need to be changed from step to step; the rest specify the size of the output image and ensure that each image will be rendered at the same scale. I’m not particularly familiar with LDView’s command line syntax, so more succinct options may be possible.
Briefly, the -cg option specifies the “latitude and longitude” of the camera on a globe whose origin is specified in LDraw units by the -ModelCenter option. The -ModelSize option controls the distance from the camera to the center of the model. These options work together to ensure the same perspective is used to depict each step. Otherwise, the different dimensions of the individual steps might result in inconsistent default camera positions.
Posted on Friday, October 19th, 2007. Tags: l3p, LDraw, LEGO, prel3p, tcl.
Google Translate Service
This service provides access to Google Translate from almost anywhere you can edit text on Mac OS X. Select some text and choose “Google Translate” from your application’s Services menu. Choose a translation from the window that pops up and click Translate. The selection is replaced with its translation.
Download Google Translate Service 67 KB
I wrote this a few weeks ago. I didn’t release it because I wasn’t completely satisfied with its behavior, although I did document some of the quirks I encountered.
I haven’t resolved those issues, but I have found the service useful—or at least amusing. So, I’ve decided to release it anyway. Consider this a prototype. The main problem is that the window containing your selection loses focus after running the service. It’s got other rough edges, too.
What’s fun is the fact that you can actually translate selected portions of web pages in Safari (interesting, since the page content isn’t otherwise editable). Other tools exist to translate web pages, and the same thing can probably be accomplished with a clever JavaScript bookmarklet, but this mechanism let you translate selectively, and it works outside the browser.
This software is not endorsed or supported by Google (or by me).
Posted on Monday, October 15th, 2007. Tags: mac.






