President-elect Obama
“Change will not come if we wait for some other person or if we wait for some other time. We are the ones we’ve been waiting for. We are the change that we seek. We are the hope of those boys who have so little, who’ve been told that they cannot have what they dream, that they cannot be what they imagine. Yes, they can.”[1]
I shy away from discussing politics online. I’m aware how hard it can be to convey nuance, and I’m also naturally one of those infuriating people who can see good intentions an both sides of most political arguments. That’s not to say I don’t have political opinions, I just don’t like coming across closed-minded; someone who is so sure of their own opinion that they would be willing to trample those of others.
I couldn’t let today pass without saying something though. Six years living in California, and living now with an American partner, I perhaps have more invested in this election than others. I am not ashamed to say that watching Barack Obama’s victory speech brought, as I am sure it did to many, a lump to my thought and a tear to my eye.
So here’s my bold statement, of the type I never make. To those who listen to Obama and say that he is nothing but a speech maker, that his orations, full of sound, signify nothing: You are wrong.
America, at its best, is a country with a remarkable amount of self-belief. That self-belief has enabled it to do remarkable things. Recently, that belief has been, for many Americans, especially the young Americans I know, lost - with no little mourning, and quite some pent-up anger. Obama will have to do more than make fancy speeches, yes, but the simple fact that America will once again be led by someone who can inspire ideas, and not just ideas, but ideals that are so good, so powerful, in so many people, cannot fail to produce good outcomes.
An inspired America is also an inspiring America. When I was growing up in Scotland, to paraphrase Obama’s words, the fire in America’s beacon did burn bright in our minds. American ideals were uplifting ideals. The UK is hardly a poor or freedom-lacking society; I can only imagine how someone in a less fortunate corner of the world than I was felt. I might be wrong, but I don’t believe that the modern America inspires those same feelings in the children of the world. An America with a renewed sense of hope and optimism, and a less circular idea of ‘right’, has a chance of rekindling that fire.
If you’re still in doubt, listen again to some of his rhetoric. Forget for a moment your logical arguments about over-simplification, or the ‘empty’ power of words. If you can’t have an open mind about the man himself then ignore him for a second. Watch the crowd, or others around you. See how they react with hope, and confidence, with an optimistic belief in their country, and also a belief in themselves. Compare it to how you remember their belief in America, manifestations of its values, and their own self-sacrifice a few years ago. Then tell me again that nothing good is happening.
[1] From Barack Obama’s “Super Tuesday” speech, February 5th 2008, in Chicago.
iPhone images from character glyphs

In which a category allowing the creation of UIImages from Unicode characters, suitable for use as Tab Bar icons, is created, but a state of mild displeasure at the implementation of said category is engendered.
Adding a ‘test’ tab to my in-development iPhone app, I had a dilemma. My troublesome aesthetic sense was telling me that, despite being seen by no-one but me, it needed a good looking icon. My sense of efficiency, though, was telling me “No! Don’t spend the time to create an icon for something no-one will ever see!”.
In the back of my brain a solution formed though. I’ve been working with Unicode recently, and there are a lot of characters you night not expect there, from the more common, like arrows (‘➡’), card suits (‘♣’), and unusual punctuation (‘‽’ interrobang - I love that one), to the more esoteric things, like scissors (‘✂’), aeroplanes (‘✈’), and skulls (‘☠’). On a Mac, you can pull-up the “Edit”→“Special Characters…” dialog and browse through them. The simplicity of many of these glyphs mean that they look well-matched to the iPhone’s interface style. Why not just use one of these ready-made images as-is? The check-mark glyph (‘✓’), specifically, seemed well-suited to my new ‘Test’ tab.
A UIImage category with the ability to create an image from a Unicode character seemed like the solution. I could just ask it for a 29x29 image of a check-mark, and I’d be set! It didn’t seem like it would be hard to write either - just render the string into an image-backed context.
Turns out it wasn’t that easy though, so as well as presenting my solution, this is a bit of a Pimp My Code post - if you can do this better, I’d like to see it, because my way seems unfortunately non-optimal (you’ll see why later).
Anyway, here’s the code:
+ (UIImage *)imageWithString:(NSString *)string // What we want an image of.
font:(UIFont *)font // The font we'd like it in.
size:(CGSize)size // Size of the desired image.
{
// Create a context to render into.
UIGraphicsBeginImageContext(size);
// Work out what size of font will give us a rendering of the string
// that will fit in an image of the desired size.
// We do this by measuring the string at the given font size and working
// out the ratio scale to it by to get the desired size of image.
// Measure the string size.
CGSize stringSize = [string sizeWithFont:font];
// Work out what it should be scaled by to get the desired size.
CGFloat xRatio = size.width / stringSize.width;
CGFloat yRatio = size.height / stringSize.height;
CGFloat ratio = MIN(xRatio, yRatio);
// Work out the point size that'll give us the desired image size, and
// create a UIFont that size.
CGFloat oldFontSize = font.pointSize;
CGFloat newFontSize = floor(oldFontSize * ratio);
ratio = newFontSize / oldFontSize;
font = [font fontWithSize:newFontSize];
// What size is the string with this new font?
stringSize = [string sizeWithFont:font];
// Work out where the origin of the drawn string should be to get it in
// the centre of the image.
CGPoint textOrigin = CGPointMake((size.width - stringSize.width) / 2,
(size.height - stringSize.height) / 2);
// Draw the string into out image!
[string drawAtPoint:textOrigin withFont:font];
// We're done! Grab the image and return it!
// (Don't forget to end the image context first though!)
UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return retImage;
}
Looking good. Now, all we have to do is use it to render a check-mark as the UIViewController subclass tab bar icon, in its init method:
self.tabBarItem.image =
[UIImage imageWithString:@"\u2713" // Unicode code for a check-mark.
font:[UIFont systemFontOfSize:
[UIFont systemFontSize]]
size:CGSizeMake(29, 29)];
Easy! So how does it look?

Hrm. It sure is nice and shiny, and it certainly looks like the image I wanted, but it’s, well, rather small. What about all that size manipulation we did? Why’s it not filling the full 29X29 pixels?
Well, we forgot that a given string doesn’t necessarily (in fact, I’d go so far as to say never does) ‘fill’ its entire bounding box. This is more obvious for letters - for example, ask how large a rendering if the string @”x” is and you’ll get a box that is basically as tall as the line height, not just the lowercase ‘x’ - but it’s true for symbols too. What we actually needed to scale was the size of the glyph’s bounding box, not the size of the rendered string.
This is where I hit a wall. The iPhone does have ways to get the bounding boxes of (and to draw) raw glyphs, but these APIs work at the font level, where glyphs have potentially font-unique arbitrary numbers assigned to them - numbers that don’t corresponding to their ‘equivalent’ Unicode characters - and there’s unfortunately no public way to convert from an arbitrary character to its glyph number. This means that there’s no way to get a bounding box for a character or string - at least, not that I could find.
What to do? I didn’t want to be defeated, so it was down to good old-fashioned bitmap manipulation. Here’s the routine again, with some extra scaling:
+ (UIImage *)imageWithString:(NSString *)string // What we want an image of.
font:(UIFont *)font // The font we'd like it in.
size:(CGSize)size // Size of the desired image.
{
// Create a context to render into.
UIGraphicsBeginImageContext(size);
// Work out what size of font will give us a rendering of the string
// that will fit in an image of the desired size.
// We do this by measuring the string at the given font size and working
// out the ratio scale to it by to get the desired size of image.
// Measure the string size.
CGSize stringSize = [string sizeWithFont:font];
// Work out what it should be scaled by to get the desired size.
CGFloat xRatio = size.width / stringSize.width;
CGFloat yRatio = size.height / stringSize.height;
CGFloat ratio = MIN(xRatio, yRatio);
// Work out the point size that'll give us the desired image size, and
// create a UIFont that size.
CGFloat oldFontSize = font.pointSize;
CGFloat newFontSize = floor(oldFontSize * ratio);
ratio = newFontSize / oldFontSize;
font = [font fontWithSize:newFontSize];
// What size is the string with this newfont?
stringSize = [string sizeWithFont:font]
// Work out where the origin of the drawn string should be to get it in
// the centre of the image.
CGPoint textOrigin = CGPointMake((size.width - stringSize.width) / 2,
(size.height - stringSize.height) / 2);
// Draw the string into out image.
[string drawAtPoint:textOrigin withFont:font];
// We actually don't have the scaling right, because the rendered
// string probably doesn't actually fill the entire pixel area of the
// box we were given. We'll use what we just drew to work out the /real/
// size we need to draw at to fill the image.
// First, we work out what area the drawn string /actually/ covered.
// Get a raw bitmap of what we've drawn.
CGImageRef maskImage = [UIGraphicsGetImageFromCurrentImageContext()
CGImage];
CFDataRef imageData = CGDataProviderCopyData(
CGImageGetDataProvider(maskImage));
uint8_t *bitmap = (uint8_t *)CFDataGetBytePtr(imageData);
size_t rowBytes = CGImageGetBytesPerRow(maskImage);
// Now, go through the pixels one-by-one working out the area in which the
// image is not still blank.
size_t minx = size.width, maxx = 0, miny = size.height, maxy = 0;
uint8_t *rowBase = bitmap;
for(size_t y = 0; y < size.width; ++y, rowBase += rowBytes) {
uint8_t *component = rowBase;
for(size_t x = 0; x < size.width; ++x, component += 4) {
if(*component != 0) {
if(x < minx) {
minx = x;
} else if(x > maxx) {
maxx = x;
}
if(y < miny) {
miny = y;
} else if(y > maxy) {
maxy = y;
}
}
}
}
CFRelease(imageData); // We're done with this data now.
// Put the area we just found into a CGRect.
CGRect boundingBox =
CGRectMake(minx, miny, maxx - minx + 1, maxy - miny + 1);
// We're going to have to move string we're drawing as well as scale it,
// so we work out how the origin we used to draw the string relates to the
// 'real' origin of the filled area.
CGPoint goodBoundingBoxOrigin =
CGPointMake((size.width - boundingBox.size.width) / 2,
(size.height - boundingBox.size.height) / 2);
CGFloat textOriginXDiff = goodBoundingBoxOrigin.x - boundingBox.origin.x;
CGFloat textOriginYDiff = goodBoundingBoxOrigin.y - boundingBox.origin.y;
// Work out how much we'll need to scale by to fill the entire image.
xRatio = size.width / boundingBox.size.width;
yRatio = size.height / boundingBox.size.height;
ratio = MIN(xRatio, yRatio);
// Now, work out the font size we really need based on our scaling ratio.
// newFontSize is still holding the size we used to draw with.
oldFontSize = newFontSize;
newFontSize = floor(oldFontSize * ratio);
ratio = newFontSize / oldFontSize;
font = [font fontWithSize:newFontSize];
// Work out where to place the string.
// We offset the origin by the difference between the string-drawing origin
// and the 'real' image origin we measured above, scaled up to the new size.
stringSize = [string sizeWithFont:font];
textOrigin = CGPointMake((size.width - stringSize.width) / 2,
(size.height - stringSize.height) / 2);
textOrigin.x += textOriginXDiff * ratio;
textOrigin.y += textOriginYDiff * ratio;
// Clear the context to remove our old, too-small, rendering.
CGContextClearRect(UIGraphicsGetCurrentContext(),
CGRectMake(0, 0, size.width, size.height));
// Draw the string again, in the right place, at the right size this time!
[string drawAtPoint:textOrigin withFont:font];
// We're done! Grab the image and return it!
// (Don't forget to end the image context first though!)
UIImage *retImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return retImage;
}
Phew! That was quite a palaver! Things would certainly be much easier if we could just ask for a string’s literal bounding box. The proof of the pudding is in the eating though, as they say. Does it work? Here’s what the check-mark looks like now:

Pretty good, if I do say so myself (and you can look again at the image at the top of the post for more examples of it working).
So; a day spent, just to save time, creating code to create an icon I could have drawn by hand in five minutes, and then more time writing a blog post about it. Still, it’s reusable - and that’s what counts! Right?…
Here’s the source in a proper format, to save your copy-and-paste fingers. Let me know if you use it, it would certainly be nice if it found some use somewhere besides my test tab. Do also let me know if you find a better way to do similar - my sense of efficiency is still reeling at all the bitmap manipulation.

[1] Check out the “Apple Symbols” font, specifically in the “Glyph” view - there’s lots of useful GUI ‘artwork’ in there. Near the end, there’s even a lot of iPhone-related glyphs. Unfortunately the font is not included on the iPhone
Inside the machine
Em’s sewing machine has been in a state of disrepair since it arrived here in her suitcase from California. Today, we finally got around to taking it apart to see what was wrong (after searching in vain for a repair manual online - it seems that sewing machine manufacturers have not yet entered the Internet age). Turned out to be a simple problem (one of the belts had slipped off, no doubt during baggage “handling”).
While it was apart, it was so fascinating to watch it in operation that we had to take this video.
Some sort of profit-making scheme¹
The FSF has published their “5 reasons to avoid iPhone 3G”. They have some valid points, but I’d be much more likely to respect them if the things like this they produced were not laden in hyperbole. The article is full of it, but one piece of ‘information’ in particular struck me:
It’s also a tracking device, and like other proprietary GPS-enabled phones, can transmit your location without your knowledge
First, GPS is passive. The phone receives GPS signals from the satellites, it doesn’t transmit them to the satellites. ‘They’ can’t track you just because you have a GPS phone. Second, (and one of the things I think makes this accusation especially insidious is that this might not be obvious to a layman reading the article, but should be obvious to the FSF), you can be sure that if software on the phone was sending your location out to ‘them’, some inquisitive geek would see the network traffic and figure it out. Third, (and making the other points almost moot), you’re using a cellphone. The phone company’s cells track your phone’s location anyway (they have to know which cell you’re in, after all). ‘They’ already know where you are.
[1] Title shamelessly stolen from John Gruber’s excellent take on the article.
someone who can take good care of 419 puppies thats alls

Spam just gets weirder. I guess this is more realistic than Robert Mugabe’s second-step-nephew wanting to wire me $10,000,000. I almost want to reply and see what “Mr Rinaggio”’s scam really is. Surely it can’t be as straightforward as getting me to pay for a dog then not delivering it to my “nearest airport”?
The fallacy of premature optimization
From a link on Hacker News (the occasionally interesting “Reddit for Erlang, Lisp and Haskell using proto-entrepreneurs”), this 2006 ACM Ubiquity article:
Every programmer with a few years’ experience or education has heard the phrase “premature optimization is the root of all evil.” […] Unfortunately, as with many ideas that grow to legendary status, the original meaning of this statement has been all but lost”
I would not agree with all the proposed solutions to the problem, but I do agree with most of the observations.
One of the most frustrating things I found when working on performance at Apple was that, almost always, user-level performance issues were caused by lots of small inefficiencies spread throughout the software adding up to noticeable chunks of wall-clock time. Issues like these were very hard to “post-optimize”: instead of one major algorithm to change, fixing the issue would require small, but still time-consuming, changes in many independent places.
Syntax of the future past
There is a fair amount of complaining on The Internets at the moment about Objective-C and Apple’s choice to use it for the iPhone. Many newcomers to the ‘platform’ (if I can apply a singular name to Mac and iPhone development) are finding the language - and the Cocoa frameworks based on it - very confusing. Just how can a language with sooooo many square brackets! be at-all easy to use, after all?
This provoked some deja-vu. Hadn’t, my vague memories asked me, this complaining been done before? I seemed to remember some talk of an “alternate syntax” for Objective-C based on dots from my first WWDC trip in 2001. I turned to the Internet.
It turns out that, yes, this has happened before. Back in 1997, in the Rhapsody days, when Aqua was but a twinkle in Steve Jobs’ eye and the iPhone would have been indistinguishable from magic, Apple was concerned that developers coming from other platforms coming to Rhapsody were intimidated by the Obj-C syntax, and that something would have to be done. The answer was to be the Modern Syntax.
There’s precious little on the web about the proposal. In researching it, I felt a bit like an information archaeologist. These were the days before blogs, remember, and the Rhapsody community was basically composed of the small number of NeXT developers so confident in the technology that they had actually managed to delude themselves into thinking that beleaguered Apple could make it successful where NeXT had failed. What little information that is still available is on Usenet newsgroups (thank you, Google, for preserving these), mailing list archives and magazine articles (remember when magazines were a source of cutting-edge information?).
The earliest references I could find were some talk of the proposal on the Omni Group’s macosx-talk list in 1997. It was plainly a serious proposal at the time. Quoting from Christopher Nagel’s message about the syntax in which he quotes from an Apple document:
“The current message expression syntax of Objective-C is based on Smalltalk. This syntax is sometimes referred to as the classic syntax. There is a proposal to create a modern syntax for message expressions based on Java and C++, because of its greater familiarity. This also is a step toward enabling developers to use either Java or Objective-C to access the libraries. You should be aware as you study Objective-C that the message expression syntax is likely to change in the Rhapsody release to the modern syntax.”
The proposal was controversial, to say the least. On the one hand, it did seem to imply that Objective-C would live on at a time where its community felt very threatened by Java (amongst other things), but on the other hand, it was destroying what some saw as the ‘beauty’ of the language, and what little concrete was leaking out of Apple about it did not appear well thought-out. The proposal did get to the implementation stage, at least within Apple, and the syntax did exist - there was even a compiler flag to turn it on, as this message to comp.lang.objectivec circa 2001 attests (although by that time, the effort had been abandoned), but I could find no concrete examples of it. This 1997 MachTech article, an interview with the authors of CodeWarrior (remember that?), shows their take on it. They obviously thought that the syntax was coming, and here to stay. No methods with more than one argument are shown though, and they say that “We will support this as a real modern syntax specification falls into place”, which implies that the syntax they show might all be guesswork on their part. If anyone has some real examples of Modern Syntax Objective-C, I would be intrigued to see them.
In the end, the revolt from the ObjC community (and perhaps also, if I was to speculate, technical arguments inside Apple akin to the ones taking place on the Omni lists that I linked to above) killed the proposal. By October 1997 - only three months after the original proposals were being discussed - this quote from an Apple Rhapsody FAQ was posted to Omni’s macosx-dev mailing list:
Q: Will you be adding "modern syntax" for Objective-C?
A: At WWDC, we discussed an investigation into a modern syntax. It became clear that Objective-C developers prefer the current syntax, and that programmers of other languages were eager to use Java as their language of choice. As a result we will focus our efforts on moving Objective-C forward and deliver a complete Java solution. The modern syntax effort will not continue
This was not the triumph that the ObjC guys were hoping for, however. By 2001, Cocoa-Java was being pushed as the next-big-thing, and Objective-C was still in for a tumultuous ride. But that’s another story.
Every inch of my love (every centimetre in the UK)

This weekend, I cleaned out the ex-belongings of the previous residents of our flat that had been sitting in the sort-of-corridor-area outside our door since we moved in (if you’ve been in our flat, you’ll know what I mean). Amongst the waitressing clothes, semi-broken electronics and Christmas ornaments was this mysterious and highly dubious looking CD. With curiosity (and a healthy dose of trepidation), I played it today. I was mightily surprised.
It turns out that the clue to what’s on it is in the title, not so much the imagery.
For your listening pleasure: eMusic, iTunes (UK), iTunes (USA).
In case of software emergency...

“Which one accurately depicts the way your software treats the user in the event of an emergency?”
From Jeff Atwood’s www.codinghorror.com. I am not sure I agree with the article completely, but I love the imagery.
PWD in the title bar (or, “A regex adventure in BASH”)

In which a five-minute hack to put the current working directory in the title bar of the Terminal descends into hours learning the surprising arcanities of BASH.
Like most developers, I spend a lot of time at my computer living in Terminal (and the rest Xcode)*. I have what might be a strange tendency to open a new Terminal window for each new task, I think so that I don’t have to lose the context in my current window. This means that after I’ve finished doing something (or in the middle, when I look at the screen and my obsessive-compulsive side grabs me and says “Wow, that’s messy. I need to tidy up my desktop before I can do more work”) I often find myself with a vast number of Terminals open, with the majority sitting minimised in the Dock, and no idea which ones are actually still useful.
In the past, I found a cool script snippet that I added to my BASH .profile that would put the current working directory in the title bar of the Terminal. This is a huge help. It means that I can quickly choose the ‘right’ window for whatever I’m doing just by looking at the title bar, or by selecting it from Terminal’s Window menu, and when I’m on one of my cleaning frenzies I don’t have to go through the windows trying to work out what I’m using them for; I can just mouse over the minimised window, see the title and (almost always) close it with the context menu.
I didn’t have that snippet any more though (the hardware it’s possibly even still on belonged to Apple, not me, and I didn’t think about retrieving it in time), but I was sure that Google would provide the answer to me.
And it did, sort of. There lots of pages on the web about configuring your BASH prompt, and even a full ‘HOWTO’. None of them gave a cut-and paste example of exactly what I wanted though. This section of the HOWTO came pretty close, but didn’t quite do it. After reading it though, my demands increased. Seeing what others had done, it seemed like it would be pretty cool if, besides having the directory name in the title bar, it was also formatted nicely. I now wanted it to be truncated to size (with ellipses, not just any old truncation), and to replace my home directory with “~/”. The snippet given there almost does this, but it smelled a bit off to me. It uses grep, awk, wc, tr, sed - a veritable cornucopia of shell commands - to do its thing. Although I’m all for the UNIX philosophy of small tools doing what they do well, it doesn’t seem like so many external processes should be required just for a bit of string manipulation (from the page: “Relative speed: the first version takes about 0.45 seconds on an unloaded 486SX25. Risto’s version takes about 0.80 to 0.95 seconds.” - of course, on my modern machine they were instant, but it’s the principle…)
So, I did some research and found something that pleasantly surprised me. Did you know that BASH actually now supports in-process regexes? Maybe I’m late to the party, bit I didn’t. You can (in the form here, since version 3.2) do this:
And the regex will be executed for you, a 0 (which, in shell land, indicates success) returned if the string matches, a 1 if it doesn’t, and a 2 if you screwed up and gave it an invalid regex. Matches for any parenthesised parts of the regex are placed in an array called BASH_REMATCH (item 0 is the entire match, items 1+ are the parenthesised expressions). It’s all even there in the BASH man page (look under “Compound Commands”). The regexes are not in the Perl format most people expect nowadays, they’re in POSIX format, as described by man re_format, but that’s not hard to pick up.
Using my new-found shell-script-regex powers, and some more of BASH’s string manipulation routines, I wrote my own pwd-to-title-bar routine, taking inspiration from the second one on the HOWTO page I mentioned before, but using all in-process string manipulation (hopefully, this will run faster on Risto’s 486SX25). Here it is:
function directory_to_titlebar {
local pwd_length=42 # The maximum length we want (seems to fit nicely
# in a default length Terminal title bar).
# Get the current working directory. We'll format it in $dir.
local dir="$PWD"
# Substitute a leading path that's in $HOME for "~"
if [[ "$HOME" == ${dir:0:${#HOME}} ]] ; then
dir="~${dir:${#HOME}}"
fi
# Append a trailing slash if it's not there already.
if [[ ${dir:${#dir}-1} != "/" ]] ; then
dir="$dir/"
fi
# Truncate if we're too long.
# We preserve the leading '/' or '~/', and substitute
# ellipses for some directories in the middle.
if [[ "$dir" =~ (~){0,1}/.*(.{${pwd_length}}) ]] ; then
local tilde=${BASH_REMATCH[1]}
local directory=${BASH_REMATCH[2]}
# At this point, $directory is the truncated end-section of the
# path. We will now make it only contain full directory names
# (e.g. "ibrary/Mail" -> "/Mail").
if [[ "$directory" =~ [^/]*(.*) ]] ; then
directory=${BASH_REMATCH[1]}
fi
# Can't work out if it's possible to use the Unicode ellipsis,
# '…' (Unicode 2026). Directly embedding it in the string does not
# seem to work, and \u escape sequences ('\u2026') are not expanded.
#printf -v dir "$tilde/\u2026$s", $directory"
dir="$tilde/...$directory"
fi
# Don't embed $dir directly in printf's first argument, because it's
# possible it could contain printf escape sequences.
printf "\033]0;%s\007" "$dir"
}
if [[ "$TERM" == "xterm" || "$TERM" == "xterm-color" ]] ; then
export PROMPT_COMMAND="directory_to_titlebar"
fiPROMPT_COMMAND is run by BASH every time it’s about to put up a prompt, so I set it (at the bottom of the snippet) to my title-bar-renaming function, directory_to_titlebar. The actual function gets the current working directory, replaces the home directory path, if it’s there, with “~/”, appends a slash and, if necessary to make the whole string fit in Terminal’s title bar nicely, snips out directories after the initial “/” or “~/”, replacing them with “…”. The escape codes in the final printf are what tells Terminal to use the enclosed string as the title instead of printing it to console. The only thing I wanted but was unable to do was to get the string to use the Unicode ellipsis character instead of the three full-stops. It seems weird in these modern times but, unless I’m missing something, BASH’s string entry routines are not Unicode-aware (if it’s possible, please do leave a comment telling me how!)
If you want to use it too, just copy it and paste it into your ~/.profile file. I believe it should work on any system that uses or emulates an XTerm, not just the Mac OS X Terminal.
The last thing to do to get what I wanted was to set the Window preferences to show the rest of the information I thought would be useful. I’ve pasted a screenshot of Terminal’s prefs on the left (this is in the left-hand pane of the Settings tab of Terminal’s prefs). The Title setting (here reading “Terminal”) is what’s replaced by the string we’re ‘printing’ in the routine above, the Active Process Name setting enables you to see what’s currently running in that Terminal in the title bar, and the Command Key option puts the window’s command key in the title bar, meaning that you can tell at a glance which window you can bring forward by pressing Cmd-2 at any time. You can see how it all works together in the screenshot at the top of this page.
And with that (phew) my marathon of BASH was over, and I could get back to what I really should have been doing all along, but with my environment made just a little bit more pleasant.
* with no time whatsoever spent in Safari, or writing complexly formatted blog entries when I should be working.