Programatically Add/Remove Menu Bar Items

Discussion in 'Mac Programming' started by Darkroom, Nov 27, 2008.

  1. Darkroom Guest


    Dec 15, 2006
    Montréal, Canada
    to add them programatically, i do this (EX: Eject item)

    NSTask *showEjectTask;
    showEjectTask = [[NSTask alloc] init];
    [showEjectTask setLaunchPath:@"/usr/bin/open"];
    [showEjectTask setArguments: [NSArray arrayWithObject:@"/System/Library/CoreServices/Menu Extras/"]];
    [showEjectTask launch];
    [showEjectTask release];
    but how is it possible to remove that same eject menu item programatically? it seems that /usr/bin/killall is only good for system apps (Safari, Finder, etc.) and that i can't set a array path for system apps to be used in setArguments.

    so neither of these work:

    /usr/bin/killall /System/Library/CoreServices/Menu Extras/
    /usr/bin/killall Eject
  2. kainjow Moderator emeritus


    Jun 15, 2000
    The reason you can open them is because they're treated like documents/packages, so they open with whatever opens .menu packages (SystemUIServer). They aren't processes, only plugins, so killall doesn't work. I'm guessing you'd have to edit the preferences plist that SystemUIServer uses, and then killall SystemUIServer to get it to relaunch.

Share This Page