NSWorkspaceDidActivateApplicationNotification

Discussion in 'Mac Programming' started by MrFusion, Aug 5, 2010.

  1. MrFusion macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #1
    I found out how to add and remove a badge to the dockicon (like the number of unread mails in the dockicon of Mail). I also know how to bounce the dockicon. The bouncing stops either after 1 second of when the user activates the program. In addition, I want to remove the badge from the dockicon when the app becomes active. The NSWorkspaceDidActivateApplicationNotification is received for every app. How do I find out if its is my app for the current user?
    Both if conditionals in the becameActive: method don't work. Any idea how to correct this? Thanks!

    Code:
    - (id)init 
    {
        self = [super init];
        if (self != nil) {
    		[[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self
    												 selector:@selector(becameActive:)
    													 name:NSWorkspaceDidActivateApplicationNotification
    												   object:nil];
        }
        return self;
    }
    -(void) becameActive:(NSNotification *)notification {
    	if ([notification object] == NSApp)
    		[[NSApp dockTile] setBadgeLabel:nil];
    
    	NSRunningApplication *runApp = [[notification userInfo] valueForKey:@"NSWorkspaceApplicationKey"];
    	if (runApp == [NSRunningApplication currentApplication])
    		[[NSApp dockTile] setBadgeLabel:nil];
    
    }
    
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
  3. MrFusion thread starter macrumors 6502a

    Joined:
    Jun 8, 2005
    Location:
    West-Europe
    #3
    I overlooked the delegate methods. My bad. Thanks for pointing them out.
     

Share This Page