The Hacks We Write
Posted November 12th, 2004 @ 01:49pm by Erik J. Barzeski
Sometimes we write stand-in code: code that does basically the same thing as what we want, but in a cheap, easy fashion. Have a look at this example from MailDrop 2. Instead of putting up a dialog box we'd have to create in Interface Builder, wire up, properly handle and dispose of, etc., we took the easy way out until we could get around to doing it properly.
NSAppleScript *as = [[NSAppleScript alloc] initWithSource:@"text returned of
(display dialog \"Name It!\" default answer \"Custom Variable\" giving
up after 10)"];
NSAppleEventDescriptor *aed = [as executeAndReturnError:NULL];
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle:
([aed stringValue] ? [aed stringValue] : @"Custom Variable")
action:nil keyEquivalent:@""];
Cheap and easy. And quite a bit of a hack. 😀
Posted 12 Nov 2004 at 6:34pm #
Cool hack. I've never used AppleScript from Cocoa, and hadn't realized it was that easy. I'll have to remember that... 🙂
Posted 12 Nov 2004 at 7:14pm #
Isn't it stunning? The entire Cocoa framework, XCode / IB and the ObjC language are what other people (you know, on that "other" platform) would consider RAD tools, and probably the most powerful ones at that. I have already seen the expression in the face of Windows people when you show them what you can do in Cocoa. Just when they thought .NET and C# were the greatest thing since sliced bread... Now imagine the look when you tell them that sometimes, you allow yourself the luxury of being even lazier than that by patching your code with Applescript "stand-ins" - you gotta love this 😉
Posted 15 Nov 2004 at 12:05am #
Were it not for the fact that NSAppleScript has a leak (http://blog.kung-foo.tv/archives/001135.php).