Monday, December 15, 2003

Keyboard Shortcuts

John Gruber and Christopher Clark discuss keyboard shortcuts. I’m more optimistic than Gruber in that I think Apple can come up with a good system for user-customizable keyboard shortcuts, without applications having to explicitly register them. Instead of having a preferences panel, there should be a more direct interface, like Menu Master’s. Apple writes the menu manager, after all. Also, Joshua Dady pointed me to /Library/Scripts/Mail Scripts/Scripts Menu, which has instructions for adding keyboard shortcuts to menu scripts.

I must admit that my own applications are currently guilty of not supporting Close All Windows and Minimize All Windows. I’m working to correct that. For Cocoa developers, here is a category that will help:

@implementation NSApplication (yourPrefix)
- (NSArray *)yourPrefixVisibleRegularWindows
{
    NSMutableArray *result = [NSMutableArray array];
    foreach ( window, [self orderedWindows] )
        if ( [window isVisible] && [window canBecomeMainWindow] )
            [result addObject:window];
    return result;
}
@end

Don’t forget to implement -validateMenuItem: so that the commands are disabled when there are no windows. OmniOutliner currently supports the commands, but gets the validation wrong.

Comments RSS · Twitter

Leave a Comment