Archive for the 'Sample Code' Category

NSWindow setResizable:

December 18, 2007

This article has been updated moved to a new location.

NSWorkspace Bug in - openFile: ?

December 7, 2007

EDITED TO ADD: I could reproduce this bug in a large project, but not isolate it in a smaller one. It is much likely for my code to have a bug then NSWorkspace. I’m still not 100% certain that this issue wasn’t my fault in some way I don’t understand. But no [...]

An AppleScript Quine

November 3, 2007

A few days ago, out of morbid curiosity, I went looking for a a quine written in AppleScript. To my surprise, I couldn’t find one.
I’d never actually written a quine before, so this was a good ‘excuse’ to make one (and brush up on some computability theory — use it or lose it).
Well, here [...]

Interfacing With (Hacking) iChat in Leopard

November 1, 2007

Before you consider using any of the unsupported hacks I’m about to discuss, check to see if existing frameworks , or iChat’s AppleScript interface, will do what you need. Any software update can break unsupported code in unpredictable ways at any time. When Leopard came out, all the hacks I had been using [...]

Getting Mac OS X Version Information At Runtime

October 31, 2007

This article has been updated, and republished here.

Better AppleScript Through Expressions

October 13, 2007

When writing a short AppleScript to complete a specific task, do not write a procedure that checks if A exists, then operates on it if it does. Instead, write an expression that operates on A, and ignore any exceptions caused by A not existing. Surrounding the statement in a try-block will ignore any [...]

NSApplicationName Inconsistencies

October 11, 2007

This article has been updated, and moved here.

Making an Application a Singleton

August 17, 2007

To make sure there is only one instance of your application running, you can use the function WeAreAlreadyRunning() from SingletonApplication.zip
WeAreAlreadyRunning() walks the list of running processes, using the Process Manager. Each process’s bundle identifier (if it exists) is compared to the bundle identifier of the calling process’s main bundle.
If you are writing a [...]

How to Implement Automatic Updating

August 5, 2007

If you are about to add automatic updating to your application (and you should), then check out the Sparkle Framework before you start. I wish I had done this before I spent a lot of time writing my own automatic updating code.
(EDITED TO ADD: this app looks promising. Ultimately a central place to [...]

Calling the command line from Cocoa

June 21, 2007

This article has been updated and moved here.