Programatically Add/Remove Menu Bar Items

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

  1. Darkroom Guest

    Darkroom

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

    Code:
    NSTask *showEjectTask;
    showEjectTask = [[NSTask alloc] init];
    [showEjectTask setLaunchPath:@"/usr/bin/open"];
    [showEjectTask setArguments: [NSArray arrayWithObject:@"/System/Library/CoreServices/Menu Extras/Eject.menu"]];
    [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/Eject.menu
    /usr/bin/killall Eject.menu
    /usr/bin/killall Eject
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    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