On my iPhone, until iOS 6, anytime music is playing a play symbol appears (and disappears when no music is playing).

How can I achieve a similar effect in the menu bar of OSX Mountain Lion?

  • Maybe a simple Cocoa App ? – Matthieu Riegler Jan 13 '13 at 1:14
  • @MatthieuRiegler, That's what I'm thinking. Hopefully something lightweight that doesn't do much/if any more then the play indicator. – bassplayer7 Jan 13 '13 at 1:28
  • For a cocoa app. It's less than 20 lines. I'll post an sample code – Matthieu Riegler Jan 13 '13 at 2:07

Here is sample code for doing this in Cocoa (you can paste it in a new XCode project and build it) :

AppDelegate.h :

    NSStatusItem* statusItem;

AppDelegate.m :

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    [[NSDistributedNotificationCenter defaultCenter] addObserver:self
                                                          object:nil]; //registering for notifications from iTunes

    [NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited]; //No icon in the dock, menubar only

    statusItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength]; // For the icon in the status bar

- (void) iTunesNotification:(NSNotification *)note {
    NSDictionary *information = [note userInfo];
    NSString* state = [information objectForKey:@"Player State"];

    if([state isEqualToString:@"Paused"]) {
        //hiding the indicator
        [statusItem setTitle:@""];
    } else if ([state isEqualToString:@"Playing"]) {
        //showing the indicator
        [statusItem setTitle:@"▶"];

The only flaw i could see in this sample is i'm using a character for the play icon and not a image. It could be a problem when the encoding messes something up.

| improve this answer | |
  • 1
    Wow. This is terrific! Thank you very much for writing this up. I put it into XCode, packaged it as an app, and am using it as of writing. I even set it to start automatically when I log in. Does exactly what I want. Thanks. Truly awesome! – bassplayer7 Jan 13 '13 at 3:27

You could look at some of the menu bar apps that control iTunes for you. Some of those may have a nice interface for that. Here are a few http://mac.appstorm.net/roundups/music-roundups/five-slick-menu-bar-apps-for-controlling-itunes/

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .