title: Snow Leopard & LSUIElement -> application not activating properly, window not "active" despite being "key"
body: <p>I'm running into a few problem with a background application that uses LSUIElement=1 to hide its dock item, menu bar and prevent it from appearing in the Command-Tab application switcher.</p>
  
  <p>It seems to be a Snow Leopard only problem.</p>
  
  <p>The application places an NSStatusItem in the menu bar and pops up a menu when clicked on. Selecting "Preferences..." should bring up an NSWindow with the preferences. </p>
  
  <p>The first thing that doesn't seem to work is that the Window does not get ordered in at the front, but appears behind all other application windows.</p>
  
  <p>I tried to fix this by calling </p>
  
  <pre><code>[[NSApplication sharedApplication] activateIgnoringOtherApps: YES]
  </code></pre>
  
  <p>but that didn't work.</p>
  
  <p>After a while I figured out that the menu is blocking the message to the run loop from being sent, so I wrote another method on the MainController and sent the message with a delay:</p>
  
  <p>[self performSelector:@selector(setFront:) 
                withObject: [preferencesController window] afterDelay:1.0];</p>
  
  <pre><code>-(void)setFront: (id) theWindow {
  
   [[NSApplication sharedApplication]activateIgnoringOtherApps:YES];
   [theWindow orderFrontRegardless];
   [theWindow makeKeyWindow]; 
          [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
  }
  </code></pre>
  
  <p>Note the send-every-possible-message-to-make-it-do-what-it-should-be-doing-approach.</p>
  
  <p>This works, kind-of, the window is brought to the front on top of all other windows from all apps, BUT most of the time it isn't active, meaning it's title bar is greyed out. Clicking on the title bar won't make the window active either. Clicking INSIDE of the window will make it active!?</p>
  
  <p>This all didn't seem to be a problem in Leopard; just calling activateIgnoringOtherApps and making the window key seemed to work just fine.</p>
  
  <p>In Snow Leopard there is a new API designed to replace LSUIElement that is supposed to emulate its behaviour:</p>
  
  <p><a href="http://developer.apple.com/mac/library/releasenotes/cocoa/appkit.html" rel="nofollow noreferrer">http://developer.apple.com/mac/library/releasenotes/cocoa/appkit.html</a></p>
  
  <p>I've played around with that, but it's SL-only and I haven't been able to get LSUIElement being set.</p>