Application running from toolbar?

Discussion in 'Mac Programming' started by brentley, Apr 16, 2012.

  1. brentley macrumors newbie

    Apr 16, 2012
    I want to know how I can write an application similar to f.lux and Dropbox that runs straight from the upper-righthand tool bar (not from the dock). Where/what should I read about in order to understand how to run an app that:

    1. Runs from the toolbar in the upper-righthand corner
    2. Runs all the time, even after reboot

  2. Xcallibur macrumors 6502a


    Jul 24, 2011
    This isn't a definitive answer more of a few hints, since I don't currently develop using Objective-C/OSX SDK. But I would think that although the application is running in the toolbar, it is still running, so is like any other application. So hiding the application from the dock whilst using a specific OSX API command for displaying a context menu from the toolbar may satisfy the first requirement.

    The second, is the setting of an applications automatic run status, in Windows, you add values to the registry which equate to applications to be run at the startup of the system. So in OSX, there is probably a property that can be set using the OSX SDK to add the application to the list of applications to run at the startup of the system.

    Maybe someone more familiar with OSX programming can give you more specific information.
  3. anedwar macrumors newbie

    Feb 10, 2012
    North Carolina
    Been a while since I had to do this but the basic steps are.

    1. Get the system status bar
    2. Tell the status bar to give you a status item
    3. Create a new menu and assign it to the status item

    so something like the following would probably work.
    NSStatusBar *systemStatusBar = [NSStatusBar systemStatusBar];
    NSStatusItem *test = [systemStatusBar statusItemWithLength: NSVariableStatusItemLength];
    [test setTitle: @"Hello"];
    NSMenu *testMenu = [[NSMenu alloc] init];
    [testMenu setAutoenablesItems: YES];
    [testMenu  addItem: [[NSMenuItem alloc] initWithTitle: @"1" action: @selector(menuItemPressed:) keyEquivalent:@""]];
    [testMenu  addItem: [[NSMenuItem alloc] initWithTitle: @"2" action: @selector(menuItemPressed:) keyEquivalent:@""]];
    [test setMenu: testMenu];
    to make your application run in the background just assign the "Application is background only" property in your application info.plist

    To get the application to run at start up have the user add a "Login Item" for you application. I'm sure there is a way to do this programmatically but I have not done so.

    To do this manually go to System Preferences -> Users and Groups
    Select the user you want and click the "Login Items" tab.
  4. thundersteele macrumors 68030

    Oct 19, 2011

Share This Page