Toggling Line Numbers and Soft Wrap in TextWrangler

As with most text editors, TextWrangler provides many options that allow you to customize the editing interface. Two settings I sometimes change are accessible only as preference options or as toolbar menu items. As I would prefer to toggle these features with a single keystroke, I wrote a pair of scripts to do the job. Two associated keyboard shortcuts later, there’s no need to display the toolbar or visit the preferences.

Toggle Line Numbers

This script toggles the show line numbers property of the frontmost text window.

Line Numbers Off Line Numbers On

Toggle Soft Wrap

This script toggles the soft wrap text property of the frontmost text window.

Soft Wrap Off Soft Wrap On

Download

The color scheme seen in the screenshots is Gruber Dark.

Installation

Unzip the scripts and put them in ~/Library/Application Support/TextWrangler/Scripts. Keyboard shortcuts can be assigned with the Set Key button in the Scripts palette, found under Palettes in the Window menu.

Posted on Monday, April 28th, 2008.

List splicing with foreach

Tcl’s foreach command is commonly used to iterate through items in a list. However, I had not realized that it can step through more than one list at once. Here’s a handy application of this property based on an example from the documentation:

proc splice {l1 l2} {
    set s {}
    foreach i $l1 j $l2 {
        lappend s $i $j
    }
    return $s
}

This procedure combines two lists into a new list comprised of alternating items from each input:

% splice {a b c} {1 2 3}
a 1 b 2 c 3

One use for this is to join a list of keys to a list of values to establish a dictionary or an array:

% set dimensions [splice {length width height} {10 16 33}]
length 10 width 16 height 33

% dict get $dimensions height
33

% array set d $dimensions
% set d(width)
16

So if you’ve got an ordered list of values you’d like to access as named fields, you can combine it with a list of field names using foreach and be on your way.

Posted on Monday, April 28th, 2008.

Sigma Notation

The for loop is a useful control structure common to many programming languages. It repeats some code for each value of a variable in a given range. In C, a for loop might look like this:

for (x=1; x<=10; x=x+1)
{
    /* do something ten times */
}

The initial parameter, x=1, starts a counter at one. The second parameter, x<=10, means the loop repeats until the counter reaches ten. The last parameter, x=x+1 (sometimes written x++), explains how to do the counting: add one to the counter each time through the loop.

In math, sometimes it may be necessary to add up a bunch of a related terms. For example, rather than write out 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10, the problem can be expressed with sigma notation as a sort of loop:

sum_{x=1}^{10}{x}

The x=1 below the big sigma starts the counter at one. The number 10 above the Σ specifies the final value of the counter. The Σ itself means to add up multiple copies of whatever follows, using integer values of x ranging from the initial 1 to the maximum 10 for each copy.

(The sum is 55.)

For simple arithmetic, this notation is hardly a simplification. However, if the terms to add are complicated, or if there are many instances of them, you’ll find this is clearly a compact and convenient way to express the sum. Plus, the Σ symbol is wicked fun to write.

The dweebs at Wikipedia have beat the programming-a-sum example to death.

Posted on Wednesday, April 16th, 2008.

What we choose to do with freedom

On the way home from my evening class, the bus stops to pick up visitors from the county jail. At the prison I can see a few rows of small barred windows uniformly lit by yellow light. The people behind those windows have no choice but to remain in their cells.

The bus drops me off a few blocks from my apartment. As I walk home, I pass rows of houses whose curtained windows are inevitably lit by the flickering blue light of television screens. The people behind those windows remain seated in their homes by choice.

So I celebrate the vagrant youths and fading elderly who live in transit on the sidewalks and buses between prison, school, and home. Theirs may be a sorry lot, but at least they have somewhere to go.

Posted on Wednesday, April 16th, 2008.

Starpacker

Starpacker is a utility that helps join Starkits and Tclkits to create stand-alone Starpacks. This can already be done with SDX, which is a superior tool in many ways, but Starpacker provides a simpler interface to this particular aspect of SDX.

Starpacker Mac OS X Screenshot Starpacker Windows Screenshot

More extensive help is included with the program.

Demonstration

Drag an application Starkit onto Starpacker, select a Tclkit, and click Pack to create a stand-alone executable for the indicated platform. The Tclkit is downloaded automatically if needed. (May not work with all Starkits.)

I recommend watching the video full screen for maximum clarity.

Download

Posted on Wednesday, March 26th, 2008.

ArtRage System Color Picker

Here is a script that helps you use a conventional color picker with ArtRage. Install it in ~/Library/Scripts/Applications/ArtRage 2. When you run the script, the system color picker will appear. Once you choose a color, it is automatically entered in ArtRage’s color picker.

Download System Color Picker for ArtRage 2 3.6 KB

This script requires access as an assistive device.

Posted on Wednesday, March 12th, 2008.

Bookmark in Yojimbo for Camino

I’ve posted a Camino-compatible version of my venerable Bookmark in Yojimbo script.

Update: Revised for Camino 1.6. New in Camino 1.6 is the ability to add any script in ~/Library/Scripts/Applications/Camino to the toolbar, so you don’t even need to use a separate script runner.

Posted on Tuesday, March 4th, 2008.

Remote Applications

BCC provides remote access to “licensed campus software”. This allows students to log in from off campus to use desktop software hosted on campus. I’m not too familiar with the protocol, but it seems like a Windows-oriented combination of VNC and X. Happily, clients are available for many platforms.

All I had to do to get started was download the Mac OS X Citrix ICA Client. Choosing a program from the access page downloads a “bookmark” that the client uses to launch the remote application.

Here’s Microsoft Word 2007 running in the background with a local application in the foreground. Sharp eyes may notice minor compression artifacts in the Word window. Connecting from across town, performance is sufficient to get work done.

Microsoft Office 2008 Ultimate Pro Premium Remote Ribbon and Bow Edition

Of course, the real benefit of this system is access to specialized professional applications, not word processors. Not all software available on campus is remotely accessible, but some of it is.

AutoCAD Mechanical Desktop 2004

You can also access a virtual Windows desktop. Handy for confirming the cross-platform compatibility of mathematical curios without the need to maintain a separate PC.

Eyeball fork not included

Remote applications of this sort are surely unsuited for many purposes. However, I think it is a viable approach for occasional use, particularly in cases where an institution provides software that isn’t otherwise practical for its members to obtain. Good for wrapping up projects without hasty trips to the computer lab, I imagine.

Posted on Monday, March 3rd, 2008.

State Abbreviations Service

Here’s a little service for Mac OS X that replaces the selected US state name with its postal abbreviation, or vice versa. If NY is selected, it will be replaced with New York. If New York is selected, it will be replaced with NY. Case doesn’t matter.

Download State Abbreviations Service 63K

Posted on Friday, February 29th, 2008.

A More Perfect Union

You’ve heard about the military-industrial complex. Have you heard about the prison-industrial complex? One in a hundred Americans are in jail. You know a hundred people. If none are in jail, consider those who stand on the other side of average. Johnny, we miss you.

Speaking of prisons, you’ve probably heard about Abu Ghraib. I want you to look at some pictures taken there. Expect blood, shit, unhappy genitalia, and healthy young women smiling over dead bodies—you know, reassuring evidence of the harsh but justifiable means that keep our world safe from cruelty and pain.

I want you to look at those pictures because I want you (friends, family, acquaintances) to think about how things like that came to happen. I don’t claim to know, myself, nor am I particularly interested in ascribing blame, but the fact that such events took place, in any context, really bothers me.

(We now return you to our regularly scheduled program of AppleScripts, LDraw, and, apparently, math!)

Posted on Friday, February 29th, 2008.