beatworm.co.uk

There is a top level navigation menu at the foot of the page

Scripting iTunes for the iPod, with Perl and Mac::Glue

I acquire new music at a relatively steady rate. I’ve been use my computer as a music library, storing my purchased music on a fileserver. Once I migrated to Macintosh, I started using iTunes to manage this process. It’s a useful solution, what small trouble I do have is usually related to my unusual configuration. I keep my music collection on an NFS filesystem, enough of a weird thing to do that I’m surprised iTunes doesn’t have more trouble with it.

A few years into this process I decided to get a portable audio player. An iPod was the obvious choice, despite the cost. Plug and go, lovely interface, Just Works™, all the usual. The 40GB model I went for was larger than my entire music library, compressed, to mp3 or increasingly to aac, with moderate settings. Synchonising is almost magically simple; set the iPod to sync ‘checked items’ and uncheck anything in iTunes you wish to exclude. I extolled the benefit of this approach to anyone who asked.

This approach will only scale so far. After several years of acquisition, the ‘checked’ set must exceed the 40GB capacity of the device. Luckily, by the time I reached it, Apple upgraded the iPod range, the new ‘classic’ guise, offering a potential 160GB storage. I toyed with one of these on display in a shop, but quickly gave it up unconvinced. I had misgivings about the new unit, foremost was the surprisingly sluggish interface.

Read the rest of this entry »

posted Thursday, January 10, 2008 at 15:44 by cms in computers, music, programming | 3 Comments »

2008 brings the changes

I detest New Year’s Eve, and I’m not an enormous fan of the Gregorian Calendar, which seems to me to be one of those aggravatingly archaic measurement systems, which whilst possessing romance and historical pedigree in gross quantities, really don’t scale too well to the modern age. And don’t get me started on time-zones

Database-nerd pedantry aside though, I do really like New Year resolutions. I like the idea of working at self-improvement, and consequently I always make a goodly set of targets for myself, mostly privately. They’re not always focused on tangible goals, and those that are I often fail to meet, but then, stretching oneself is sort of the point.

Probably the silliest scheme I’m going for in 2008 is to quit drinking alcohol. Not that I think I have a problem, as you’re traditionally obliged to add as a follow up to that statement. As a regular alcohol user though, I do think it will present an interesting challenge, and I suspect it will have a generally beneficial effect on my health, and also my bank balance. I’m in good company too, it seems like Richard Herring is joining me on my quest.

I’m going to leave myself the cop-out clause, of still allowing champagne. Firstly, it allows me to join in the toasts at significant social gatherings. Secondly, it lends an air of faux-class, as by champagne, I mean your actual champagne; none of your prosecco or cava, thanks very much. Thirdly, if I find myself regularly buying crates of champagne at bulk discount for home consumption, I’ll have good grounds to accuse myself of hiding a drink problem.

Another good thing about breaking in a new year, is that it encourages change. I’ve already indulged in some long-neglected home improvement work, and I’ve extensively rebuilt and replumbed this website to use the WordPress system for the blogging bits. The base URL has changed, and there’s now a wider variety of detailed feeds. I’ll endeavour to maintain all the old permalinks and feeds with redirects, and I’ve migrated all the old content across. There is bound to be breakage, so let me know if you spot anything.

Previously, I was using a publishing system which started out as the marvellously simple blosxom, which progressively grew less marvellous and more complex as I hurriedly hacked new features into it on demand, or whenever the mood caught me. Blosxom is ace, and if the idea of a blogging tool that is just a perl script that builds static content and uses text files within the filesystem instead of a database strikes you as intriguing, you should definitely give it a go.

Blosxom development seems to have stagnated for a long while, although there’s recently been more activity, and my slapdash customisations had grown crufty and brittle enough to make my publishing environment fragile, and irritating to change. And so, WordPress. This brings all sorts of new features I’ve been asked for, but too lazy/busy to add in the past (comments!), extensibility and an active development, and it’s based on the industry lowest-common-denominator combination of apache / PHP / mysql, so I can keep control of my own content, yet can easily move it to pretty much any cheap-ass hosting provider under the sun if needs be.

And as an added benefit, I expect I’ll be posting more frequently, at least until the novelty wears off.

posted Wednesday, January 9, 2008 at 17:33 by cms in computers, uncategorized | 1 Comment »

Elisp and AppleScript

Since I switched to using Macintosh predominately, I’ve tried a few different programs for editing text. I auditioned some of the available Macintosh native applications. The built in text editor, “TextEdit” is surprisingly useable, although it no longer offers much specific programming support. XCode has a capable editor, with IDE features for Macintosh application development, but it’s too slow and large to be more generally useful. The power editor on Macintosh always used to be “BBEdit”, but it’s expensive, and seemed complicated and old-fashioned. TextMate is very interesting, an attempt to bring together UNIX editing concepts with the OS X application frameworks, and I was nearly tempted to switch to it full time, but I eventually decided to stick with the editor I know best, GNU emacs.

It turns out that that’s not as straightforward a decision as it might seem. There’s a variety of different emacs implementations on offer. Apple ship a version of emacs 21 in /usr/bin, but it’s purely a terminal based application that has to run in an emulator window. This works well enough, but has restricted font rendering, and your editor session isn’t an application instance at the top level, being subprocess of the terminal application. You could compile a GUI emacs using the Apple X11 server, which improves the font handling, but still would be a sub-application process, and would introduce the usual klunky X11 clipboard integration. There are also a few ‘native’ Emacs application ports. Andrew Choi has ported both GNU Emacs and XEmacs to the Macintosh OS X carbon APIs, and there is something called “Emacs.app” which is an update of the NeXT Emacs port to a more modern emacs base.

I seem to have settled on using the Carbon emacs port, in a new variant that uses the ATSUI text rendering framework rather than QuickDraw. This seems to fix some of the very ugly font rendering behaviour I used to sometimes see with Carbon emacs. I suspect I am probably rather oversensitive to font rendering accuracy. I think this new engine is only available in the CVS tree for emacs, but this is quite simple to install on a Mac using MacPorts.

sudo port install emacs-devel +atsui

A remaining niggle is the use of emacs in server mode. Emacs is rather a heavyweight application, taking some seconds to load, and it carries a lot of state. Ideally you want to perform all of your editing in a single emacs session, rather than starting a new editor anew each time. Emacs has a client/server mode to allow you to do just this. Simply add

(server-start)

to your .emacs file to start the server, and use the emacsclient program as your editing tool. This contacts the running server and creates a new buffer for the invoked editing context. Setting your environment variables for EDITOR and VISUAL means that shell commands will use the emacs server as your default editor.

The niggle is that you then have to switch window context to edit. And as autoraise and raise-window do not seem to have any effect on Carbon Emacs, you have to manually find the emacs window for the server that is waiting for your edits, probably buried under a pile of windows. I’ve managed to go some way to fixing this problem with an unholy marriage of elisp and AppleScript.

The AppleScript

Tell application "Emacs" to activate

will raise the running emacs frame and switch focus to it. There is a command line program provided with OS X, osascript that can run AppleScript programs from script files, or run one-liners via the -e argument. It is therefore possible to add some elisp to the emacs initialisation scripts to automatically run the AppleScript snippet.

(defun my-server-visit-hook()
       (interactive)
       (shell-command
	  "osascript -e 'tell application
	     \"Emacs\" to activate'"))

(add-hook 'server-visit-hook 'my-server-visit-hook)

Every time a server buffer is created, this hook will be called, and emacs will raise itself to the front of the window stack, steal focus and prompt for input, which seems to be mostly what I’d want. I have yet to devise a manner of returning to the calling window context after editing, which will probably be a less trivial hack.

posted Sunday, December 3, 2006 at 21:23 by cms in computers, programming | Comments Off

FileVault confuses aging Unix fan

Apple have been providing the ability to securely encrypt your home directory for the last few versions of OS X. The cute name they have for this is FileVault. It’s largely a transparent business, and perhaps useful to have if your data might be found lying around somewhere, so I tend to enable it for portables.

It’s not entirely invisible. During use, your home directory changes to a spiffy modified icon. Logging in, and working with very large files seems to be slightly slower, and it prompts you to reclaim space on logout, which can take quite a while if you’ve recently re-organised a lot of data. And there’s a few more obscure differences that might show up. I was recently bitten by one of these, and perhaps it’s a testament to how seamlessly FileVault is slotted into the system in that it took me a little while to figure out what was going on.

I’d been playing around with some toy code for some co-operating daemons, and I was tweaking a section that might open some files read-write, to check that they would work with minimal access permissions. On a mac I tend to do all my development work inside my home directory, much like I do everything else. So I changed the ownership of my exectuable to a dummy user, enabled the set-user-id bit, locked down my data file’s permissions, and ran the tests. I wasn’t particularly suprised when it failed with access errors. First pass, my code, bound to be wrong.

I double checked the permissions and ownership, files owner only, process owned by the right uid, setuid bit on. I read the man pages for chmod and chown again. Still no joy. I fished out a copy of APUE and wrote the simplest possible test case. It still wouldn’t work. Whatever sequence of library or system calls I tried, the effective user id of the subsequent process was always me.

After a while I figured it out. When you enable FileVault for a user account, your home directory has a binary file called yourloginname.sparseimage within it. This is your FileVault home directory, in the form of a sparse encrypted disk image. When you login to your account, this image file is transparently mounted under $HOME, using the OS X disk image framework. When you logout, it’s unmounted again. You can manually mount it from a shell using the hdiutil tool like this

hdiutil -stdinpass -mountpoint /Users/foo /Users/foo/foo.sparseimage

You’ll get a prompt for the image password, which will be the same as the UNIX account password. You need to type the null at the end of the password, which you can do with C-@, before you hit return. If you type mount you’ll see the disk image listed in the mount list. You will also notice the default options for disk image attachments is to mount them with the nosuid attribute. This causes OS X to silently disregard any set-user-id attributes of files within the filesystem. This makes a lot of sense as a security measure, and is commnly used for filesystems on removable media. You don’t want foreign filesystems introducing set-user-id binaries into your local filesystem on an ad-hoc basis as they are mounted.

Your own securely encrypted home directory doesn’t really represent a similar security risk, especially if you’re already the main administration account for your mac, and so the precaution seems less useful here. I wondered if it was a deliberate policy decision, or a side effect of the disk image framework. I’m not sure if you can mount disk images without nosuid at all.

When manually mounting filesystems, nosuid is an optional property supplied to the mount command. It seems like it ought to be possible therefore to mount disk images without the nosuid attribute being passed through to mount , but I haven’t yet managed to find a way to influence the mount options passed from hdiutil. Nor have I found where the magical FileVault attach happens, or if there is any way to influence it’s settings. In practice, it doesn’t really matter much, as set-user-id binaries have a very limited use, and probably shouldn’t be encouraged to proliferate.

posted Tuesday, October 31, 2006 at 00:57 by cms in computers | Comments Off

Continuing the story of the powerbook battery replacement

A week later, I phoned back as suggested. I used the number from the apple store shipment tracking form, as before. I did as I had been told, and read out my incident number to the representative who answered This time, the Apple Store support chap pointed out I was dialling the wrong number for technical support, before offering to transfer me to the right department.

Immediate connect. A reasurring Irish accent enunciating an Applecare support menu. I select ‘other’. Less than five minutes on hold. Nice jazz at a reasonable volume, rather than distorted techno-metal. A friendly, intelligible voice takes the call, takes my case number, and then puts me on wait for another couple of minutes while he digs out the details.

He returns to confirm everything I’d managed to deduce from the UPS number. An order had been created with UPS, and they’d been credited, but no shipment collection had ever been made. He’s checked with the dispatch team, and the battery order is there, ready to go. He’ll chase it up with UPS, and anticipates it should be delivered to me within a couple of days. I explain about the useless tracking number on my battery program confirmation email, and he tells me that these are from an entirely separate order numbering systems to the store, you need to phone technical support. I grumble a bit about the wait time, he’s very apologetic.

This is the Apple support I’m used to. Ok, someone screwed up, but they’re on to it, and it didn’t take more than ten minutes of my time to let them know. Why so different from last week’s call center hell ? My best guess is that it has to be the valid incident case number. Presumably, if you hand out Applecare credentials or a case number early in the chain you get fast-tracked to a higher tier of support. A further conclusion to draw; for Apple laptops, which in my experience are more likely to feature technical problems than their desktop machines, Applecare should probably be considered a mandatory part of the purchase cost.

posted Thursday, October 26, 2006 at 16:37 by cms in computers | Comments Off

More fun and games with Apple Customer support

There’s a small, persistent chorus of dissent that echoes around the net, a companion to the peculiar cult of Apple worship that purchasing a Macintosh computer seems to bring out in some consumers. “Apple computers are all very nice”, it goes ” but they’re overpriced, and tend to be unreliable” . I’m not really sure how much truth there is to it, but like anything repeated more than three times on slashdot, it’s approached the state of a received wisdom amongst that particular strain of technophiliac. Nerds love dogma.

It’s not a very significantly-sized sample, but I have owned/managed six modern Macintosh systems, and my strike rate for hardware problems is exactly 50%. Perhaps interestingly, it’s been entirely limited to the notebooks. I’m not sure if this spells anything significant itself. I can certainly see how portable computers might undergo more stress as part of their normal wear and tear. One trend I am getting a little tired of is what seems to me to be the plummeting standards of product support at Apple.

My powerbook, the same one that originally started me thinking about questionable standards of support , is one of the lucky models that was sold with a battery that’s subject to a recent safety recall. There’s been a lot of this happening recently, to various brands of laptop. From what I’ve read, it’s all down to contamination in the cells, a flaw at the factory manufacturing the base cells that go into Lithium-Ion batteries. This contaminant means the batteries can get too hot in operation, and when hot, potentially catch fire or explode. The cells in question were produced by Sony for assembly into laptop battery packs for various other computer brands. In fact, Apple seemed to be making a point of this, highlighting the fact that the batteries were made by Sony, and mentioning in a subsequent press release that Sony would be picking up the tab for the free replacement program Apple have set up to handle the recall.

So I typed in my serial numbers into the web form, and sure enough my battery was a dud. I was advised to stop using it immediately, and wait for a free replacement. This might take from four to six weeks to ship. This means my portable won’t be very portable for a month or so, which is irritating. On the other hand, I’m going to get a factory new battery, which will probably have a larger charge capacity than my worn in one. Also I didn’t catch fire or explode. Overall, a net positive I think, with some minor inconvenience.

Nine weeks later, there’s been absolutely no sign of this replacement battery. I’ve been getting progressively more twitchy about this after the minimal four-week period passed. I’ve got a confirmation email about the transaction with a tracking number, which fails to work in their online order tracking system. I don’t ever seem to have much luck with Apple store shipments. This one is now well overdue, and I realise I’m going to have to give them a call to try and chase it up. I’m reluctant, remembering how terrible the last session was, but I’m getting increasingly suspicious that something’s gone wrong with the process, and I’ve had a functionally restricted computer for the past two months now.

So I make the call to the support number offered on the useless web tracking form. The robot reads out a menu, with an option for tracking orders or shipments. I press the indicated number. A robot tells me to use the web tracking form, and hangs up on me. Irritated, I redial, and this time wait and choose the ‘Other enquiries’ option. Five minutes or so on hold and I get picked up. Heavy accented English once again, perhaps an off-shore call centre. I explain I’m trying to track a battery replacement for a powerbook G4. I’m asked if I have a reference number. I give him the tracking number I was originally sent by the email robot. There’s a short pause while he does his thing with the number. He asks ‘Is this a battery replacement?’, sounding a little suprised. Declining to point out that I’ve already explained that it is, I agree. He’ll have to transfer me to another department.

Forty-five minutes on hold. Forty-five minutes of obnoxious pop music, too loud for the phone, distorting. So loud I have to hold the receiver a few inches away from my face. Every couple of minutes the volume drops and a voice starts speaking, so I’m compelled to listen closely once more in case it’s a pickup. It’s a robot, telling me a representative will be answering as soon as possible. And then the music blasts in again, deafening. These call queues are a horrible variant on the traditional bus-stop dilemma. Hang up after twenty minutes? What if the mean queue time is twenty-five, and I’m only a few minutes from an answer? I have to make the call, it’s my only realistic avenue of support. What if the next time it’s a forty minute average wait ? Better to stay on the line.

At the end of this ordeal, I’m answered by a female, again an accent, sounds off-shore. She explains helpfully that I’m through to iPod support, asks about the nature of my problem. I’m so stunned I have to ask her to repeat this. She confirms it’s iPod support. I manage to say something about having been put through to the wrong department by the previous operative, but I’m almost lost for words. I think my mood must be detectable from my voice, because she volunteers to see what she can do, referencing other departments. I hand over my details, including all the serial numbers, and the useless tracking number. I’m put on hold for another ten minutes while she looks things up. Thankfully this time it’s just quiet elevator muzak. Not often you find yourself grateful for bland piped music.

She returns with a UPS tracking reference. It doesn’t elucidate any detail other than the information that it was billed and shipped on the 20th of September, with a destination of Bristol, UK. This seems likely to be mine. She tells me that she will escalate this incident, gives me a ticket number, and tells me to call back in a week if it hasn’t fixed itself.

Overall I find this to be a fairly shocking standard of product support. I’m a moderately competent computer user, I wouldn’t bother to trouble the support line for usage or software problems, or anything self inflicted. In all cases I’m calling because I’ve purchased an expensive piece of consumer electronics that has proven to be mechanically faulty as supplied. I can accept that accidents and mistakes can occur, but I’m not sure it makes economic sense to keep purchasing products from a source that seems to guarantee I’ll be spending months waiting for inevitable faults to be corrected (taking into account the previous hardware fault, this powerbook will now have had fifteen-plus weeks of outage/reduced functionality), and spending multiple hours chasing up the state of these orders and repairs.

Another interesting data point is that the first two support incidents I ever reported to Apple were handled magnificently, super friendly support lines, and whizzy next day turnaround on replacements and repairs. Whereas currently, the root of the trouble I’m getting is entirely down to customer service, which although it’s polite, and ultimately helpful, is too unresponsive, and close to incompetent. I’ve got two working theories as to what has changed.

  • At the time they were impressing me with customer service, I had valid Applecare for one of the Macintoshes in the house. Perhaps you get a better tier of support if you’re a registered Applecare customer. Unfortunately the only way I can test this hypothesis is by buying another Macintosh, and buying some Applecare, and waiting for a fault, or faking one for test purposes. This plan is both expensive, and perhaps morally dubious.

  • Now that Apple have become a mainstream consumer electronics company, selling iTunes and iPods to the Dixons crowd, they’ve had to dramatically streamline their support costs in order to scale to this market size.

Either way, I’m slightly ticked off. I think Apple products are good value for what they offer. I’m a big fan of the software. In particular, I think the modern Mac OS represents the least irritating computer environment I’ve worked in yet. I appreciate that sounds like faint praise, but I think it’s quite a measure of acheivement. I’ve been working with software and computers long enough now, that I appreciate that most of the skill in system design is centered in, for want of a better term, the process of suck-removal. I really appreciate that all the NeXT technologies and principles still have a viable platform, almost twenty years after their inception.

The trouble I have is that commiting oneself to using Macintosh means a commitment to a single supplier. Nobody likes feeling like they’re being peddled a lower quality deal because of a vendor-contrived platform lock-in. The increasingly fashionable anti-Windows grumbling, that Apple are cheeky enough to allude to in their current television advertising, is rooted in a similar sentiment, borne of a peculiar, voluntary form of modern serfdom; indenture to an unsatisfactory software platform in return for maintaining compatability with the status quo. There would be a certain kind of irony in Apple managing to parallel this antagonism by fixing the software, but in turn locking you to a hardware promise they’re not capable of delivering. I wonder how I’ll be feeling about this after the suggested week’s wait.

posted Friday, October 20, 2006 at 18:19 by cms in computers | Comments Off

Quicksilver keybindings

Quicksilver is one of the very best things you can do with your Mac. I adore it. To describe simply, it superimposes a keyboard interface over the Macintosh interface in a very natural way, directly appealing to any keyboard junkie.

Most quicksilver operations involve navigating a hierarchy of lists, precisely the sort of thing that would be a frustrating exercise in imprecision with a mouse. Navigating them by typing is a breeze. Incremental search, next and previous item, forwards, backwards. Until recently, I had thought that the directional commands were restricted to the arrow keys, which was unfortunate as I dislike reaching for the arrow keys on most keyboards. C-n and C-p work for next and previous as they tend to in many Cocoa applications, but for forward and back I was still using the left and right arrows in the inverse ‘T’.

No more. I recently discovered that ‘/’ and ‘?’ were bound to these commands, much closer to the home row. Further reading led me to discover how to customise these bindings. Like most things Quicksilver, this is barely documented. Creating a property list file at

~/Library/Application Support/Quicksilver/KeyBindings.qskeys

with contents like this

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>QSSearchObjectView</key>
	<dict>
		<key>^f</key>
		<string>moveRight:</string>
		<key>^b</key>
		<string>moveLeft:</string>
	</dict>
</dict>
</plist>

Will allow C-f to move forward into a list, and C-b to move back up, which is more in line with how my fingers expect applications to work. The master definition file can be found in the application bundle

Quicksilver.app/Contents/Frameworks/QSInterface.framework/Versions/A/Resources/DefaultBindings.qskeys

and should give some ideas about things that you can set. Scanning through the default actions that are bound is an education too. I’m not even sure what half of the entries represent yet.

posted Thursday, June 15, 2006 at 19:01 by cms in computers | Comments Off

Tricks with terminal windows

I have always been a big desktop, more pixels sort of person. Since GUI desktops became the norm, I’ve always strived for the maximum desktop resolution I could afford, and fit on the desk. And when I’m gifted with the expanse I feel I’m deserved, I invariably fill it with clutter. Vast arrays of overlapping windows, obscuring dozens of dubious desktop icons.

I’m not sure that this approach represents any kind of advantage, although it’s perhaps an insight to the way my mind works; my physical desktop is a direct analogue, in terms of accumulated clutter. It does mean I’m reliant on the window management features of my computer to help me make sense of the mess.

Different software systems offer various techniques for desktop management. I’ve tried most of them. Mac OS X scores fairly well. The menu bar location is consistent with it’s omnipresent Window menu. Command-tab switches between running applications, Windows-style, and command-~ does similar things with the active application’s windows. Windows miniaturise themselves to the dock with that amusing ‘genie effect’ scaling, and zoom back up just as easily.

There are flaws, of course. Window resizing is a bit of a pain, and there’s a lot of mousing, on a big desktop the application menu can seem miles away from it’s window, which makes one grateful for keyboard shortcuts. The Dock is a curious and inconsistent thing that doesn’t seem to deserve the prime screen space it demands in order to be even mildly useful

Best of all is the stupidly-named ‘Exposé’ feature. You’ve probably seen it in action, or perhaps one of the legion of kludgy knock-offs for other desktop systems. A flick of the mouse, and the unnavigable cascade of open windows are scaled and zoomed and ordered to fit on your display. Pick one and they all fly back, with your selection promoted to the front position. It’s immensely clever and useful, and quite essential. and quickly became one of those ‘muscle-memory’ things that make you look and feel stupid if you subsequently try to operate a system which doesn’t have it.

Given a large enough desktop area, this method of navigation works well, even for quite large collections of windows. Different applications are recognisable even when reduced to postage-stamp dimensions, and multiple documents like web pages are usually distinguishable by their content, down to similarly modest proportions. Sadly, it all falls down when it comes to terminal emulator windows and this is unfortunate because I tend to always have many of these open at once.

shot of cluttered desktop shot of cluttered desktop after exposé

An old joke about the X window system used to be that it was a very resource intensive way to display two dozen xterm windows at once and a desktop clock. The humour of this may be questionable, but like most mocking jokes, it is built around a truth. The sheer utility of the Unix command line shell in experienced hands is really hard to beat for interactively munging text, and managing files. And munging text and dealing with filing still seems to describe the majority of computer use. Furthermore, the terminal and command shell interface, having evolved from slow serial lines and dialup teletypes, is really efficient for remote use. Working with networked systems, far away or nearby is often best served by popping open a shell and logging in.

Add to this the thirty to forty years of applications that have been built on top of the assumption that the ersatz teletype is the one true way, and it becomes clear why, despite all the developement efforts channeled into fancy-pants ‘Desktop Environment’ GUI software over the last decade, many heavy Unix users inevitably use their GUI as a convenient way of swiching between umpteen concurrent shell sessions in terminal windows. At least I do.

I’m slightly better on the mac, the GUI is so pervasive and coherent, I tend to make more use of the file management tools. But one of the reasons I like the mac is that it’s a nearly-unix underneath all the tinsel, and so the command line still gets plenty of exercise and the terminal windows gather. And they all look frustratingly similar when tiled by exposé.

Colour seemed like an obvious approach. Amongst the many command arguments you can start an xterm with are -fg and -bg switches. These set the foreground and background colours to one of the named X color resources, respectively. By colouring your terminals differently you get the handy extra visual mnemonic you need to distinguish them when they are shrunken down to tiny tiles. These colours are fixed at launch and harder to type, and make a good candidate for shell aliases. They also don’t apply to terminal emulators that aren’t based on xterm, such as Apple Terminal ones. It would be better if you could set these colours interactively in a way that was portable across terminal types. As I suspected, it turns out you can do exactly this, by inputing special escape sequences.

Using a command like

 echo -e "\033[40;1;33m"

you can send control characters to an xterm to set the foreground and background colours of the text. Then, redrawing the screen via ‘clear’ will leave you with a terminal window that has bold yellow text on a black background.

echo -e "\033[42;1;31m"

would give you bold red text on bright green. Easy to spot at any size, and it works in Apple Terminal too!

The breakdown of how this works is as follows. The -e argument to echo means that it will use its own escape sequences to interpret non-printing characters. \033 is the octal code for ESC. The string recipe is actually ESC then [ which intiates the sequence, followed by a list of numeric attribute codes separated by semicolons and then the charcter m. The following table lists some of the ANSI display attribute codes codes that are useful.

Attribute Description
1 Bold
2 Normal (not bold)
4 Underline
5 Blink
7 Inverse video
8 Invisible
30 Foreground black
31 Foreground red
32 Foreground green
33 Foreground yellow
34 Foreground blue
35 Foreground magenta
36 Foreground cyan
37 Foreground white
40 Background black
41 Background red
42 Background green
43 Background yellow
44 Background blue
45 Background magenta
46 Background cyan
47 Background white

Using the table, you can construct escape strings to dynamically change the color of your terminals.

 echo -e "\033[32;47m" ; clear

would change your colors scheme to green text on a white background, for example. The drawbacks are obvious. The numbers are hard to remember, and the string is tricky to type. This calls for a gross hack! I define three butt-ugly functions in my bash profile that simplify this process greatly. They’re listed below.

function _fg {
    case $1 in
	y)
	    FG="1;33"
	    ;;
	g)
	    FG="1;32"
	    ;;
	r)
	    FG="1;31"
	    ;;
	p)
	    FG="1;35"
	    ;;
	W|w)
	    FG="1;37"
	    ;;
	b)
	    FG="1;34"
	    ;;
	B)
	    FG="1;30"
	    ;;
    esac
}

function _bg {
    case $1 in
	y)
	    BG="43"
	    ;;
	g)
	    BG="42"
	    ;;
	r)
	    BG="41"
	    ;;
	p)
	    BG="45"
	    ;;
	W|w)
	    BG="47"
	    ;;
	b)
	    BG="44"
	    ;;
	B)
	    BG="40"
	    ;;
    esac
}

function xtc
{
    FB=$1
    F=$( echo  | cut -c1 )
    B=$( echo  | cut -c2 )
    _fg $F
    _bg $B

    CMD="\033[${BG};${FG}m"
    echo -e $CMD && clear

}

The way this works is I get a short mnemonic comand xtc to use for changing the terminal color. I define the colors as single letter constants, in separate helper functions for both foreground and background colours. Then I can just use type xtc rb to instantly refresh the terminal I am using to be bold red on blue. I can then use this as a memory-aid, by assigning distinct colours to different terminals as I use them. This makes them easy to pick out when shrunk. A kludge, but a handy one to have about

shot of exposé applied with a varicoloured terminals

posted Friday, March 24, 2006 at 16:39 by cms in computers | Comments Off

Apple Mail revelations

All mail clients suck. I say this often.

I’m fairly welded to the Mac OS X mail client. It’s free, comes with the computer, and does a reasonable job of supporting the sort of email standards that you need to be able to post to nerd mail lists without getting shouted off stage.

It’s got a nice interface, albeit one which Apple keep shunting about radically with each new OS release; particularly so in the case of the 10.4 update where they gave it a strange new skin and widget set unlike anything else in their oft-lauded UI guidlines, and broke the IMAP support so badly I had to rebuild my entire mail server just to keep using it. I suppose this is indicative of just how attached I am to the application. Or some weird software-user abusive relationship cycle I’m psychologically locked into. It’s a habit.

Some of this is down to the integration. Seeing as the authors own the hardware and the OS platform, they can link the mail client into their bundled software in much the same way that Microsoft get shouted at for attempting to do. This is undeniably handy, the system-wide address-book, sync services, messaging and calendaring all co-operate with each other with pleasant synergy.

Some of the attraction is familiarity. I’ve been using ‘Mail.app’ for a long time. Years. If I were more pretentious, I could try and act as if my NeXT dabbling entitled me to claim it was decades. Like most network-centric people, email is quite fundamental to my computer-life, and upheavals there might have a wide domino effect. I’m resistant to change.

Mostly though, I think the attraction is down to functionality. It just has some hands-down-unbeatable features, that other clients don’t manage to match. Ranging from the obvious ( lovely mac fonts and text input system ), to the subtle ( I’ve configured color coding quotations at indent level in progressively paler shades of blue so that the older citations gradually fade towards white ), to the magnificent ( only quoting the currently highlighted text in a reply, every mail client should have this feature ).

Not only all that, but I keep unearthing new useful features, which is what has prompted me to write. In the past month, I’ve stumbled across two excellent capabilities that have refreshed my enthusiasm for this workhorse software. I’ve no idea how long they’ve been present.

  1. Clicking on the little replied-to icon in the list pane immediately opens your reply in a new window
  2. Multiply selecting mail folders ( i.e. with Command-click ) presents the contents of both in the list pane. I cannot believe I’ve never noticed this before today

Reading this back it occurs to me that I recently found a blog seemingly dedicated to Apple Mail tips. Some or all of these suggestions may well have come at me from this source. It’s interesting reading.

posted Tuesday, February 21, 2006 at 18:47 by cms in computers | Comments Off

Computer trouble

The site has been effectively offline since the start of December, due to hardware trouble. Seeing as I barely manage to update it monthly, I’m sure this service interruption was only irritating to me. The trickle of users who hit it from googling for dalmatian photos would not have been able to discern the problem, you’ll be glad to hear. It was a hardware problem of the offline variety.

My powerbook developed a fault with its motherboard, ‘logic board’ in Apple-speak. The fangly new scrolly-touchpad which I was foolishly and boastfully proud of when it arrived has a temperature sensor associated with it. I know this because it was this particular sensor that failed. Sporadically, the laptop would shutdown fast. I ignored it the first one or two times, they were probably months apart. By the next escalation, it would immediately drop to sleep in a half hour. The logs showed that it was shutting down in response to an ‘emergency thermal overtemp’ condition. I wondered if it mightn’t be getting sufficient airflow in its customary position on the desk. The case wasn’t hot, or even warm to the touch.

Pretty soon these clusters of outages were coming twice-weekly or more. Still no unexpected heat. Judicious googling using the log messages turned up a small gaggle of mac users with similar symptoms on forums and blogs. All with similar powerbook models to mine – 15″ aluminium case, USB ‘two-finger scroll’ touchpad. A few of them suggested that they’d isolated the problem to the trackpad thermal sensor using monitoring software. I downloaded some software called ‘Temperature Monitor.app’. It didn’t take long to confirm. The powerbook started having one of its power-off tantrums soon enough, and the logs produced by the monitoring software indicated that the trackpad sensor was recording temperature fluctuations between -70 and +270 degrees Celsius, within the space of a couple of minutes. In itself amusing, but by now the computer had degenerated further and become unusable, making it harder for me to appreciate the funny side.

At this point I shall note that since ‘switching’, I’ve bought three models of Apple laptop, all of which have suffered some kind of spontaneous component failure. Perhaps all the talk about Apple product reliability has some foundations after all? I’m enough of a crap statistician to realise that three subjects isn’t really a useful sample population. The failures do represent a rather disappointing coincidence. Over the same time period I’ve made home for three desktop Apple models, all of which have performed without trouble, which doesn’t help really signify that much of a trend. Anecdotal evidence, especially any gleaned from web discussions, I think is largely worthless. I did find this informal survey which generally suggests an even distribution. It is mildly interesting that all my three problems are specifically marked in red as significantly prone to fail on the model by component chart (iBook G3 800 logic board, Titanium powerbook G4 800 Optical drive and Aluminium 15″ powerbook trackpad). If only I was this successful at picking lottery numbers! I might win ten pounds.

One positive thing had emerged from my run of unlucky laptops. Apple customer support had been wonderful. Although the titanium had been covered by AppleCare, the iBook was out of warranty; in both cases after a pleasant phone call to an unquestioningly helpful support line, they arranged to courier the laptops back to the mothership and returned them back after 24 hours in a working state. This time I was less impressed. My powerbook was not covered by AppleCare, but was only 8 months old, I genereally prefer to wait a while before purchase, to try and spread the cost. It took a fair bit of grubbing around the Apple website to find an appropriate looking telephone support contact. I dialled it, and worked my way through the automated menu system towards the ‘Help, my computer is borked’ options.

After waiting on hold for the usual half hour or so of canned music and messages, I was put through to a heavily accented man, who, whilst being unfailingly polite, and ultimately quite helpful, still managed to live up to every unfortunate offshore-call-centre cliché going; I was repeating everything he said back to him for confirmation, and repeating most of my own answers similarly until we were confident about agreement, several times we resorted to spelling things phonetically. All of this over a premium rate call I was paying for, of course. After running through his scripted heuristics, pre-charging my credit card for a support incident, and him explaining to me where to find the hardware diagnostics disc (It’s the same DVD as the software restore these days – who knew?), he was able to confirm what I already knew, my powerbook had a hardware fault with it’s trackpad, and that this would entail a logic board replacement, which was covered by standard warranty.

I was surprised to hear that there’d be no magic courier this time. Instead I needed to take it to my local service centre. In Belfast. It took several attempts at spelling and pronunciation to discern this was what he was saying. I live in Bristol. Belfast, Ireland might not be quite within a separate country, but it is about as close as you can get to that without leaving the UK. There’s a different island involved. Ten minutes of explaining why this was bad and I got a second suggestion out of him. Western Computer, a fairly local Apple shop I don’t tend to frequent. Apparently I would have to phone them myself and arrange a repair.

I don’t particularly want to use this space to complain about Western. I don’t like the shop particularly, I find the staff aloof, and indolent, and I get an impression of long-entrenched smug mac-user superiority from the whole place that I’m entirely ready to believe is a product of my own imagination. They have weird opening hours policies that preclude weekends. Whatever the reason, I tend to prefer to spread my shekels on other soil. Still, they were pleasant enough on the (promptly answered) phone, although they did ominously explain that they were rather backlogged with repairs, invited me in to see what my options were

When I arrived they were friendly enough, although not particularly enthusiastic. I went through the whole story with the support technician chap, and he looked my serial number and confirmed that it would be a warranty repair job, probably a motherboard replacement, and that they’d only charge me for the examination if their own investigation proved there to be no fault. They couldn’t examine it then and there, there was a queue system. Oh, and there was a minimum four week wait for a repair of this time, what with it being Christmas, and something to do with iPods I didn’t quite follow. I could perhaps try going to the Cardiff Apple Centre as an alternative. Again, with the other country treatment. Admittedly Wales is fairly close, but still a few hours travel there and back. Probably not a huge saving over a flight to Belfast. I didn’t seem to have many options. I asked the chap if they had a lot of broken powerbooks in. He said, no, they were really reliable. Perhaps that’s why they didn’t have many repair staff handy.

In the end it took six weeks. While they didn’t seem to be terrifically proactive about it, I can’t really call too much fault on Western’s part. The few times I chased them they replied to my calls and were happy to discuss the details of the job. I can understand that they had a backlog of work, or had to wait a longer time on parts from Apple (my powerbook is a custom web build), or shut the store completely for two weeks over Christmas, to a certain extent – I find it harder to understand why Apple are referring faulty products to a dealer with such rudimentary servicing facilities.

As I work from home, and live off my mac, managing for a month or so without a computer really wasn’t an option for me. I spent a couple of hours trying to cobble together a replacement linux computer from spare parts, but I couldn’t manage to get anything capable of driving my super-sci-fi TFT display satisfactorily. It was obvious that I was going to have to spend some money on a new computer. Attending a local LUG meeting, and sketching out my problems to a friend elicited the suggestion that I should just buy a mac mini to be getting on with – a drop in replacement that could tide me over, and ideally would hold its value for resale better than a generic pc box over the same period. This proved to be excellent advice. I picked up a mini from John Lewis, and have to say that they are excellent little machines. If you’re reading this and have been wondering about getting one, I’d say do it now. It was slower than I was used to, particularly the little disk, but overall a more capable Macintosh than I’d have thought possible for the price. Still, I’m either out of pocket over what should have been a guaranteed repair job, albeit with another, admittedly very nice, computer I don’t really need.

Luckily enough I have an effective, automated backup system (what’s your excuse? Data loss is inevitable, and common), so all in all it was only a day or so in total to swap the two systems in and out.

Lessons learnt

  • Full backups and a disaster recovery plan should be considered essential for any computer you care about. (Yay me!)
  • AppleCare is not an optional extra
  • Trust your gut instincts about retailers
  • Mac minis rock!
  • Apple hardware should not be regarded as any more or less reliable than standard PC kit, and their customer service probably shouldn’t be either
  • For Apple equipment, it may make most sense to purchase stock hardware from a retailer with a sensible goods exchange policy, rather than the Apple Web Store

Given recent hardware trends, Apple are becoming decreasingly different from standard ‘name’ PC vendors. The sole points of deviation within this whole experience and what I’d expect from someone like Dell is now really just down to the cost, and the software. Lucky for Apple, I really like the software. At this point in time, I feel like I’m paying a significant premium for a license to use it. I wonder if it will still seem a good deal in twelve months time when I’m pricing up my next laptop against a marketload of almost identical intel-based systems running Free Unix.

posted Tuesday, February 7, 2006 at 05:21 by cms in computers | Comments Off