Skip to content

Instantly share code, notes, and snippets.

@festivia
Created January 31, 2016 06:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save festivia/55641144129863f53452 to your computer and use it in GitHub Desktop.
Save festivia/55641144129863f53452 to your computer and use it in GitHub Desktop.
//
// main.m
// Simple iTunes
//
// Created by Colt on 4/13/13.
// Copyright 2013 __colt__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
int main(int argc, char *argv[])
{
return NSApplicationMain(argc, (const char **) argv);
}
//
// Simple iTunes.h
// Simple iTunes
//
// Created by Colt on 4/13/13.
// Copyright 2013 __colt__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface Simple_iTunes : NSObject {
NSStatusItem *statusItem;
IBOutlet NSMenu *statusMenu;
}
@end
//
// Simple iTunes.m
// Simple iTunes
//
// Created by Colt on 4/13/13.
// Copyright 2013 __colt__. All rights reserved.
//
#import "Simple iTunes.h"
@implementation Simple_iTunes
-(void)awakeFromNib {
statusItem = [[[NSStatusBar systemStatusBar] statusItemWithLength:NSVariableStatusItemLength] retain];
[statusItem setHighlightMode:YES];
[statusItem setTitle:@"iTunes"];
[statusItem setMenu:statusMenu];
[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(updateTrackInfo:) name:@"com.apple.iTunes.playerInfo" object:nil];
[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(iTunesTerminated:) name:NSWorkspaceDidTerminateApplicationNotification object:nil];
}
-(void)updateTrackInfo:(NSNotification *)notification {
NSDictionary *information = [notification userInfo];
NSLog(@"track information: %@", information);
if ([information valueForKey:@"Display Line 2"]) {
[statusItem setTitle: [NSString stringWithFormat:@"%@", [information valueForKey:@"Display Line 1"]]];
}
if ([information valueForKey:@"Artist"] &&
[information valueForKey:@"Name"]) {
[statusItem setTitle: [NSString stringWithFormat:@"%@ - %@", [information valueForKey:@"Name"], [information valueForKey:@"Artist"]]];
}}
-(void)iTunesTerminated:(NSNotification *)notification {
NSRunningApplication *runApp = [[notification userInfo] valueForKey:@"NSWorkspaceApplicationKey"];
if ([runApp.bundleIdentifier isEqualToString:@"com.apple.iTunes"]) {
[statusItem setTitle:@"iTunes"];
}}
-(void)dealloc {
[statusItem release];
[super dealloc];
}
@end
//
// Prefix header for all source files of the 'Simple iTunes' target in the 'Simple iTunes' project
//
#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#endif
//
// Simple_iTunesAppDelegate.h
// Simple iTunes
//
// Created by Colt on 4/13/13.
// Copyright 2013 __colt__. All rights reserved.
//
#import <Cocoa/Cocoa.h>
@interface Simple_iTunesAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end
//
// Simple_iTunesAppDelegate.m
// Simple iTunes
//
// Created by Colt on 4/13/13.
// Copyright 2013 __colt__. All rights reserved.
//
#import "Simple_iTunesAppDelegate.h"
@implementation Simple_iTunesAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment