Category Archives: Blog

Extensions are not enough

Another thing I like about Mac OS X is [the print preview available in any software][printing] that chooses to provide printing (unless that software [chooses to be awkward][acrobat]).

Acrobat dialog box being unhelpful as ever

Best software ever

When this feature first appeared, one could trigger a stupid bug if one happened to have an application other than Preview.app set as the default application for files with the `.pdf` extension. If you had Adobe Acrobat set as your default PDF viewer, then hitting the preview button in print dialog boxes would open that preview in Acrobat.

It was a stupid bug, particularly because it was so obvious what was going wrong. The preview was being written to a temporary file with a `.pdf` extension and then being opened using whatever handler was defined in launch services. But you don’t want that, you want it to be handled by the operating system and not be subject to whether or not you have the patience to wait thirty seconds while Acrobat version 6 merrily paints its splash screen for your pleasure.

Later versions of Mac OS X fixed this so that the print preview is *always* displayed using Preview.app. This happens even if you set Acrobat as the default application for `.pdf` files, and it is a good thing it behaves like this. (In fairness, launch times for Acrobat since version 8 are no longer painful.)

*I tested what happens if you delete Preview.app on a clean 10.5.8 install: the system falls back to opening QuickTime Player.app for displaying previews (which works fine). And if you delete QuickTime Player.app it falls back to using Safari.app (also works fine). And if you delete Safari.app it falls back to TextEdit.app (which works fine as long as you can render raw PDF data in your head).*

It is as if going by the default association between file extension and application was not enough; that the system had a need to use a particular bit of software for these PDF preview files, regardless of what software was chosen as the handler for a different set of PDF files. Who’d have guessed?

All of this is an argument for providing a **programmatic** way to set the owning application for a file. You might call this a creator code, potentially any file could have one, but no biggie if it was not present because you could fall back to some regular stupid heuristic for determining the owner.

And then in Mac OS X 10.6 you might [change the behaviour of the system][106] so that [this useful and important information about the file is ignored][ars]. Grumble.

Dammit, only just occurred to me to see whether the system would eventually fall back to using Acrobat itself for displaying previews. Grumble.

[printing]: http://support.apple.com/kb/HT3771
[acrobat]: http://www.adobe.com/products/acrobatpro/
[ars]: http://arstechnica.com/staff/fatbits/2009/09/metadata-madness.ars
[106]: http://db.tidbits.com/article/10537

More mail bombs

[Tim Gaden over on Hawk Wings][hawkwings] [doesn’t agree][agree] that [Mail.app’s behaviour regarding deleting POP accounts is misguided][bomb].

His first point is that Mail.app gives you a big warning before doing the dirty. I don’t think that excuses the bad behaviour. Warning someone that you behave badly does not excuse that bad behaviour (my ex says this rule applies in more cases than the implementation of mail clients).

His second point is that the user should have a backup; with a good backup she can recover from her mistake when all those old messages disappear. I agree that people should have backups, but I don’t think that argument has any weight because you can imagine that the answer for all bad design decisions is “you should have had a backup”, in which case there are no bad design decisions.

The problem is that Mail.app’s insistence on a POP account being a separate set of folders means a message cannot appear in the Inbox unless it belongs to an account. If you delete a POP account then you have to move the messages to the Inbox of another account just to keep them appearing in the Inbox. This does not make sense.

Suppose you have a large history of messages received via a POP account. Then you delete that account and switch to an IMAP service with a meagre storage limit. If you want to keep those old messages appearing in the Inbox you must move your the historic Inbox messages to the IMAP account’s Inbox even though that will take up space on the server (and there may not be sufficient space on the server for them anyway). The other option is to give up the idea that old messages belong in the Inbox and just move them to local folders “On My Mac”.

If Mail.app provided a local Inbox folder that appeared as part of the unified Inbox then my objections would go away. (There should also be a corresponding local Sent folder.)

IMAP and POP are different in that a POP account’s mailbox is really just a temporary queue for messages that have yet to be retrieved by the client. Mail.app should recognize that difference and stop pretending that the two types of account are equivalent.

Quite pleased that Hawk Wings even knows my blog exists. Hawk Wings is good.

[hawkwings]: http://www.hawkwings.net/
[agree]: http://www.hawkwings.net/2010/07/07/mail-apps-disappearing-pop-mail-trick/
[bomb]: http://reliablybroken.com/b/2010/07/apple-mail-bomb/

A digression on Entourage

[Microsoft Entourage][entourage] is such an interesting piece of software. It evolved from (Mac) Outlook Express which was a great mail client for the old Mac OS (despite its grumpy IMAP implementation). Outlook Express itself took many of its design cues from Claris Emailer, to the extent I believe the early versions of Outlook Express were [coded by peeps who had worked on Claris Emailer][emailer].

I always liked that Outlook Express and Entourage defaulted to plain text for messages. I particularly liked the fact that OE / Entourage defaulted to bottom-posting when replying to a message – as any fule kno top-posting is a hideous convention foisted on us by miserable office mail systems back when there was still a chance that your e-mail would not be delivered via SMTP (Exchange version 5 and earlier is the primary culprit here).

I still get annoyed that when using Mail.app hitting the tab key in a plain-text e-mail inserts a tab character instead of expanding it to four spaces like Entourage.

Given enough time this post would devolve into arguments about [top-posting versus bottom-posting][netiquette], the width of [the one true tab-stop][tabs] and how [HTML e-mail][html] has turned our youths’ minds into mush.

[entourage]: http://www.microsoft.com/mac/products/entourage2008/
[emailer]: http://blog.entourage.mvps.org/2007/05/in_the_beginning.html
[netiquette]: http://www.faqs.org/rfcs/rfc1855.html
[tabs]: http://www.jwz.org/doc/tabs-vs-spaces.html
[html]: http://www.birdhouse.org/etc/evilmail.html

Apple mail bomb

[Apple’s Mail.app][mailapp] has an approach to mailboxes for [POP mail accounts][pop] that has never made sense to me. At least, I can see that it is a logical approach, but I don’t think it is a good approach because it can easily lead the user to inadvertently delete messages.

The problem is related to how Mail.app stores messages for an account. For an [IMAP account][imap] (or a [Microsoft Exchange account][exchange]) Mail.app creates a folder on the local disk and creates mailboxes within that folder corresponding to the mailboxes on the server. The contents of those mailboxes are synchronised with the contents of the mailboxes residing on the server. This makes perfect sense because with IMAP because the messages live on the server – keeping a local copy of those messages is effectively a performance optimisation.

What is weird is that Mail.app uses the same strategy for POP accounts, even though with POP there is only one mailbox on the server and it is effectively a temporary store for messages, which is to say that with a POP account a message does not live on the server but moves from one mailbox to another until it reaches its final resting place, that place being on the client.

The only copy of a message received via POP is on the client. (Having said that, [Gmail’s POP support][gmailpop] muddies the waters because [issuing a DELE command][dele] does not actually delete the message from the server, but the principle is the same.)

Now when you go to remove an IMAP account Mail.app deletes all the local mailboxes for that IMAP account. This is not a problem, after all those local mailboxes are simple caches; the only reason the client keeps a copy is as a performance optimisation (as noted above).

Now when you remove a POP account Mail.app deletes all messages sent or received via that account, even though there will be no copy of those messages on the server (especially true for sent messages). This is not useful or intuitive – it is a bad design.

Why is this a bad design? It is a bad design because with an IMAP account you understand that the messages live on the server whereas with a POP account you understand that the messages live on your local hard drive. With an IMAP account you understand that removing the account removes your access to those mailboxes that exist on the server, whereas with a POP account it makes no sense that the act of stopping the retrieval of messages from the account implies that all the messages received via that account and now stored on your hard disk should be removed as well.

Earlier versions of Mail.app had an even more destructive behaviour when removing a POP mailbox. In the version of Mail.app that shipped as part of Mac OS X 10.4, if you removed a POP account then _all messages associated with that account were removed without warning_. Now imagine the not uncommon sequence of events for someone changing from POP account A to POP account B using earlier versions of Mail.app:

1. User accumulates years of e-mail using POP account A.
2. User adds new POP account B.
3. User removes POP account A.

At step 3 the user lost all her historic e-mail! Apple finally realised that this was no way to win friends and so introduced a confirmation specifically warning that messages would be lost before deleting a POP account (this change was introduced with Mac OS X 10.5).

Another unfortunate behaviour is how Mail.app handles a disabled POP account. Disabling an account stops Mail.app from using that account for sending and receiving but also removes all the associated messages from the Inbox.

It is possible to keep an old POP account enabled so that its messages are still displayed but then turn off the preference to “Include when automatically checking for new messages”. This leaves the old account available when composing a new message as a choice in the From field so one must also change the preference for “Send new messages from” to always use the new POP account in order to avoid inadvertently sending a message using the old From address (or edit the from address in the old account to match that in the new account).

[Microsoft Entourage][entourage] has a better approach to this situation: messages for POP accounts are delivered to the Inbox mail folder “On My Computer”, and they stay there when the POP account is deleted. The flaw in Entourage’s approach is that the local folders appear even when all your e-mail accounts are server-based (i.e. all IMAP and / or Exchange accounts). I think it would be better to create those local folders only when a POP account has been defined because if you have only server-based accounts then it is distracting to have a set of folders called “On My Computer” which have no purpose.

[mailapp]: http://www.apple.com/support/mail/
[pop]: http://en.wikipedia.org/wiki/Post_Office_Protocol
[imap]: http://en.wikipedia.org/wiki/IMAP
[exchange]: http://www.microsoft.com/exchange/
[gmailpop]: http://mail.google.com/support/bin/answer.py?answer=13273
[dele]: http://tools.ietf.org/html/rfc1939#page-8
[entourage]: http://www.microsoft.com/mac/products/entourage2008/default.mspx

Growl for president

It is fun talking to geeks who have recently converted to Macintosh coming from a career with Windows. They are excited about the possibilities of using all those Unix tools from the command-line (and who wouldn’t be excited about that?) and are disoriented by the differences.

I tell them that a lot of things are the same, that their new computer will still go wrong in frustrating ways and that the Finder is the way it is for historical reasons. The most productive part of the conversation is suggesting bits of software that make your computing career on Macintosh less painful…

[Growl!][growl] What a fantastic piece of software. [Mac OS 9][macos9] introduced modeless notifications and it was immediately obvious why it was a good thing. Before then you could bring a Mac server to a halt just by holding down the mouse button for too long, and many Mac applications wanted to get your attention by throwing up a global dialog box to let you know when something had happened. Due to the classic Mac relying on co-operative multi-tasking a modal dialog box could not only interrupt the front-most application but also stop all background applications until the dialog box was dismissed. So Mac OS 9’s mode-less notifications were a great thing.

On [Mac OS X][macosx] there is no built-in API for posting global mode-less notifications. Growl fills that gap. Growl provides [an API for Mac applications to post notifications][growlapi] and it presents those notifications in an unobtrusive manner, floating small windows on the top of your desktop that can be easily dismissed or ignored.

The truly great thing about Growl is how it has been adopted by developers. [BBEdit][bbedit] uses Growl; [Cyberduck][cyberduck] uses Growl; [pretty][transmit] [much][fontexplorerx] [every][adium] [great][colloquy] [Mac][netnewswire] [application][transmission] supports Growl because it is such an excellent way to post notifications.

An example of Cyberduck's upload complete Growl notification

And so it seems to me that Mac OS X itself should support a Growl-like API for notifications. Either the operating system should take advantage of Growl when a user has installed it or Apple should just ship Growl as part of the system to provide its functionality as a standard API for any application to post notifications.

I believe there is a need for such an API. Witness the [Google Notifier][gnotify] application which does _not_ use Growl for notifications but instead chooses to post floating mode-less notification windows that look an awful lot like Growl’s notifications but which behave in a subtly different manner. Annoying.

[growl]: http://growl.info/
[macos9]: http://www.apple.com/support/macos9/
[macosx]: http://www.apple.com/macosx/
[growlapi]: http://growl.info/documentation/developer/
[bbedit]: http://www.barebones.com/support/bbedit/arch_bbedit92.html
[cyberduck]: http://trac.cyberduck.ch/wiki/help/en/howto/growl
[adium]: http://adiumx.com/
[colloquy]: http://colloquy.info/
[netnewswire]: http://netnewswireapp.com/
[transmission]: http://www.transmissionbt.com/
[transmit]: http://panic.com/transmit/
[fontexplorerx]: http://www.linotype.com/fontexplorerX
[gnotify]: http://toolbar.google.com/gmail-helper/notifier_mac.html

Station To Station

I am pretty sure my favourite [David Bowie][bowie] album is [Station To Station][s2s]. I am pretty sure my favourite Bowie track is *Station To Station* off that same album.

When I am invited to appear on [Desert Island Discs][desert] I will choose *Station To Station* as the one song I can take with me – it is flipping ten minutes long, and on a desert island I will want a song that takes a long time to understand and doesn’t repeat too often on my walkman.

*Station To Station* is great because it is at least two songs in one, if not three. The opening section has the discordant stop / start rhythm of a steam train getting up to speed and Bowie’s lyrics are intelligible while being sufficiently dense that I can’t sing along without a dictionary.

And then the song breaks into the second section with a solid disco rhythm interrupted by Bowie expressing the joy and uncertainty of a new love affair before we finally hit the chorus which takes the rest of the song to the end.

> It’s not the side-effects of the cocaine, I’m thinking that it must be love.

Oh my gosh it is fantastic.

It is likely that if I can’t take *Station To Station* to my desert island I will take the prelude from [*Tristan Und Isolde*][tristan], also about 10 minutes. Failing that maybe *Something Against You* by [Pixies][pixies].

[I am one happy prick][something].

[bowie]: http://www.davidbowie.com/
[s2s]: http://www.teenagewildlife.com/Albums/STS/Title.html
[desert]: http://www.bbc.co.uk/programmes/b006qnmr
[tristan]: http://en.wikipedia.org/wiki/Tristan_und_Isolde
[pixies]: http://www.pixiesmusic.com/
[something]: http://www.youtube.com/watch?v=jNrtSWup_Tg

Office 2008 update includes Entourage EWS

Not that the [release notes have any mention of it][1], but the [Microsoft Office 2008 12.2.5][2] update will also install the latest [Entourage EWS 13.0.5][3] if you had it on your hard disk already (else you get vanilla Entourage updated). You only need to install the stand-alone update if this is the first time you are installing the Exchange Web Services version of Entourage.

Microsoft’s Mac installers are good, but unnecessarily complicated. And the design of the [Mactopia website][4] drives me up the wall – tiny little scrolling `

` blocks and javascript hyperlinks makes it difficult to read the information and difficult to link straight to an update.

[1]: http://support.microsoft.com/kb/2028864
[2]: http://www.microsoft.com/mac/downloads.mspx?pid=Mactopia_Office2008&fid=D46255BD-6470-4106-9FE2-EA67ACD3F1BD
[3]: http://www.microsoft.com/mac/downloads.mspx?pid=Mactopia_Office2008&fid=EC991D3B-6B25-41C3-9119-D0E6985F2FC1
[4]: http://www.microsoft.com/mac/

Xcode and Mercurial .hgignore

For future reference, culled from [Peter Hosey][1] and [Ben Clark-Robinson][2], a mostly useful `.hgignore` definition for use with an [Xcode][xcode] project stored in the [Mercurial version control system][mercurial].

syntax: glob
*.pyc
.DS_Store
._*
*.xcodeproj/*.pbxuser
*.xcodeproj/*.perspective*
*.xcodeproj/*.mode*

syntax: regexp
^build/

*Ugh* to `.DS_Store` files and *gaaaaaah* to resource forks wedged into dot-underscore files. *Yay!* to regular expressions.

[1]: http://boredzo.org/blog/archives/2008-03-20/hgignore-for-mac-os-x-applications
[2]: http://mozketo.com/mercurial-hgignore-for-xcodecocoa/
[mercurial]: http://mercurial.selenic.com/
[xcode]: http://developer.apple.com/technologies/tools/xcode.html

Death or beachball

[Pierre Igot][igot]’s post about [Adobe’s use of a new cursor in CS5][cs5] draws attention to how Adobe is continuing to fail to adhere to Macintosh user interface conventions.

But I disagree that the correct cursor to use for a blocking task that cannot be cancelled is the spinning beachball of death. That cursor after all is the cursor automatically provided by the operating system when an application is _not responding to input events_. As such when I see the beachball I associate it with a stuck application, one that may need to be forcibly quit.

Previous versions of Photoshop showed the watch cursor for actions which took a significant length of time. Showing the watch cursor is friendlier than showing the beachball of death because it indicates that the application is busy, too busy to handle your clicks but everything is hunky dory and the train _will_ arrive at the station.

There is no watch cursor listed in [Apple’s documentation on cursors][cursors]. However the cursor is still present in the system and can be found in the headers for the carbon appearance manager:

kThemeWatchCursor = 7, /* Can Animate */

If you have Xcode 3.2.2 installed you can find this in `/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Carbon.framework/Versions/A/Frameworks/HIToolbox.framework/Versions/A/Headers/Appearance.h`, line 634.

I don’t know enough about Macintosh programming to say whether it is possible to employ this cursor from a Cocoa-based application.

[igot]: http://www.betalogue.com
[cs5]: http://www.betalogue.com/2010/05/18/cs5-cursor/
[cursors]: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ApplicationKit/Classes/NSCursor_Class/Reference/Reference.html

More Python features that I really like

Another thing that makes using [Python][python] pleasing is decorators. [A decorator is a wrapper for a function][decorators] (or method) that takes a function (or method) as an argument and returns a new function (or…) which is then bound to the name for the original function.

The newly-decorated function can then do things like checking the called arguments before invoking the original un-decorated function.

[Django provides decorators for authentication][django] so that you can wrap a view function with a check for client credentials before deciding whether to return the original response or a deny access.

In this manner Django’s authentication decorators encourage orthogonal code: the logic for displaying a view is separated from the logic for deciding whether you should be permitted to see the view’s output. By keeping them separate, it becomes simpler to re-use the authentication logic and apply it to other views.

Suppose you have a view that accepts [a Django request object][request] and checks whether the user is signed in:

def administration_page(request):
if request.user.is_authenticated():
return HttpResponse(“Welcome, dear user.”)
else:
return HttpResponseRedirect(“/signin/”)

With a decorator you can simplify and clarify things:

@login_required
def administration_page(request):
return HttpResponse(“Welcome, dear user.”)

For older versions of Python (pre 2.4) [which don’t understand the `@` operator][syntax] one must explicitly decorate the view function like so:

def administration_page(request):
return HttpResponse(“Welcome, dear administrator.”)

administration_page = login_required(administration_page)

Note in the example that the original `administration_page` function is passed to the decorator. The `@` syntax in the first example makes that implicit but the two are equivalent.

The implementation of a decorator is interesting. It takes the function itself as an argument and returns a new function which does the actual checking. Here is how the decorator used above might do its stuff:

def login_required(view_function):
def decorated_function(request):
if request.user.is_authenticated():
return view_function(request)
else:
return HttpResponseRedirect(“/signin/”)

return decorated_function

_The actual [implementation of Django’s `login_required` decorator][login_required] is considerably less idiotic. Python’s [functools module][functools] has helpers for writing well-behaved decorators._

Because functions in Python are themselves objects the decorator can accept a function reference, construct a new function that checks for authentication and then return a reference to that new function.

Simples!

(Simples gets less simples when you want to write a decorator that accepts configuration arguments because you then need either another layer of nested function definitions or a class whose instances can be called directly, but I’m going to ignore you for a bit and _wow is that Concorde…?_)

[python]: http://www.python.org
[decorators]: http://docs.python.org/reference/compound_stmts.html#function
[django]: http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.decorators.user_passes_test
[request]: http://docs.djangoproject.com/en/dev/ref/request-response/
[syntax]: http://docs.python.org/whatsnew/2.4.html#pep-318-decorators-for-functions-and-methods
[functools]: http://docs.python.org/library/functools.html
[login_required]: http://code.djangoproject.com/browser/django/tags/releases/1.2.1/django/contrib/auth/decorators.py