Ewnay Awingsdray
Here are a few recently scanned drawings:
Also, don’t miss my contributions to the inexplicable Bears in Ill-fitting Hats group:
Posted on Friday, December 21st, 2007.
Minimal Tcl/Tk Mac Application Packages
Here is one way to create a self-contained double-clickable Tcl/Tk application for Mac OS X.
Code
Save this text as hello.tcl
:
package require Tk
pack [label .l -text "Hello, World!" -padx 30 -pady 30]
For clarity, save this and other example files to the Desktop.
Tclkit
Download and unzip 8.4.16/tclkit-darwin-univ-aqua
from the Tclkit download matrix. This is a universal binary version of the latest stable release of Tcl/Tk with native Mac OS X interface elements.
Update: On Mac OS X 10.5 (“Leopard”), at least with current X11 patches, you can use non-Aqua Tclkits as the basis for Mac application packages. X11 will open automatically. Since Tk Aqua doesn’t play well with Leopard, this may prove to be a useful (if ugly) interim solution.
Updatier: The Leopard compatibility problems alluded to above appear to be resolved in Tcl/Tk 8.4.17. Tclkits of 8.4.17 and the official 8.5.0 release are now available.
Updatiest: You can now build your own tclkits with ease using the Kitgen Build System.
SDX
Download sdx.kit
from the SDX web page. SDX is a utility that can, among other things, create executable Starpacks by joining Tclkit interpreters with your Tcl code. (Safari may warn that the file is executable and append .sh
to its name; just remove the .sh
after downloading.)
Files
Open Terminal and change to the directory containing these files:
cd ~/Desktop
Make an executable copy of the Tclkit.
cp tclkit-darwin-univ-aqua tclkit
chmod +x tclkit
The duplicate is needed because Tclkit is used both to execute SDX and as input to SDX. It cannot otherwise operate on itself.
Starpack
Create the Starpack by “quick wrapping” the sample code:
./tclkit sdx.kit qwrap hello.tcl -runtime tclkit-darwin-univ-aqua
This yields the executable file hello
, which you can run from the command line:
./hello
Different Tclkits can be used to create executables for different platforms. Omitting the -runtime
argument creates a platform-independent Starkit which can be executed by an external Tclkit. Instead of qwrap
, more complex projects can use the wrap
command to package their entire directory structure as a virtual filesystem.
Icon
Every application needs a good icon. This is not a good icon, but it will suffice as an example:
Img2icns is a handy utility for converting images to icns
files.
Package
Create a folder called Hello World.app
. Because the app
extension designates an application, the Finder will treat the folder as an application package. Control-click the embryonic application and select “Show Package Contents”:
Create a folder called Contents
inside the package, and two folders titled MacOS
and Resources
within Contents
. Drag hello.icns
into Resources
and the hello
executable into MacOS
.
Info
Every application contains a file that lists certain application properties. Because some properties identify the very components that comprise the application, the application won’t work without this vital file.
Here is an example Info.plist
. Place this file in the package’s Contents
folder.
Note that the CFBundleExecutable
property identifies the executable (found in MacOS
) and that CFBundleIconFile
identifies the application icon (found in Resources
). The CFBundleIdentifier
and CFBundleSignature
properties should be unique to your application. The CFBundleGetInfoString
, CFBundleShortVersionString
, and CFBundleVersion
properties specify your application’s version.
Consult Apple’s Property List Key Reference for more details about these and other possible application properties. As XML files, property lists can be edited with text editors or Apple’s dedicated Property List Editor (included with the developer tools).
Showtime
The application package should now be organized like this:
Hello World.app
/Contents
Info.plist
/MacOS
hello
/Resources
hello.icns
It may be necessary to temporarily rename the application in order for the Finder to recognize the new package information. Hello World.app
will adopt the hello.icns
icon. Give it a double-click:
The default menu bar items and window title are provided by Tk. The internal main.tcl
filename is introduced by qwrap
.
So, that’s a tidy way to package a Tcl/Tk program for Mac OS X deployment. The application package is really just a few folders, an icon, and a property list wrapped around a Starpack. If you’re already using Starkits, you’re only a few steps away from delivering a relatively well-integrated Macintosh version of your application.
Credit
The technique described here is largely inspired by Kevin Walzer’s How to Build Tcl/Tk Application Bundles the Mac Way tutorial. The companion article on Tk Aquafication offers more guidance on integration with Macintosh interface conventions.
The example Info.plist
is based on the property list included in the Tcl/Tk Aqua 8.4.16 standalone Wish Shell, which I cannot find listed on any relevant web sites. As with other recent releases, it seems to be available only by direct download from mailing list announcements.
Posted on Saturday, December 8th, 2007.
Select Grep
Update: Now located at https://github.com/anoved/Finder-Scripts/tree/master/Select%20Grep
This script for the Finder is derived directly from the venerable lselect. Rather than select files whose names match a certain pattern, Select Grep selects files whose contents match a certain pattern.
Subdirectories are not searched and the pattern is not case sensitive. Extended regular expressions are supported. Compatibility with binary files has not been tested. The specific options given to grep
are -liE
. The script is easily edited to use different option combinations; please share any improvements.
Put the script in ~/Library/Scripts/Applications/Finder
and run it to select files in the frontmost Finder window that contain the search pattern.
Posted on Saturday, December 8th, 2007.
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
nib
files compatible with Yojimbo 1.5.
I haven’t tried the indispensable widescreen hack yet.
Posted on Wednesday, December 5th, 2007.
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.
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.
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.
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.
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.
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.