Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

2 Answers 2

up vote 5 down vote accepted

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
                                                        selector:@selector(iTunesNotification:)
                                                            name:@"com.apple.iTunes.playerInfo"
                                                          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.

share|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
add comment

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/

share|improve this answer
1  
Bytecontroller is a good lightweight menu bar app awil.no/bytecontroller –  Kyle Cronin Jan 13 '13 at 2:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.