Uli's Web Site
[ Zathras.de - Uli's Web Site ]
Other Sites: Stories
Pix
Abi 2000
Stargate: Resurgence
Lost? Site Map!
 
 
     home | blog | moose | programming | articles >> blog

 Blog Topics
 
 Archive
 

15 Most Recent [RSS]

 Less work through Xcode and shell scripts
2011-12-16 @600
 
 iTunesCantComplain released
2011-10-28 @954
 
 Dennis Ritchie deceased
2011-10-13 @359
 
 Thank you, Steve.
2011-10-06 @374
 
 Cocoa Text System everywhere...
2011-03-27 @788
 
 Blog migration
2011-01-29 @520
 
 All you need to know about the Mac keyboard
2010-08-09 @488
 
 Review: Sherlock
2010-07-31 @978
 
 Playing with Objective C on Debian
2010-05-08 @456
 
 Fruit vs. Obst
2010-05-08 @439
 
 Mixed-language ambiguity
2010-04-15 @994
 
 Uli's 12:07 AM Law
2010-04-12 @881
 
 Uli's 1:24 AM Law
2010-04-12 @874
 
 Uli's 6:28 AM Law
2010-04-12 @869
 
 Uli's 3:57 PM Law
2010-04-12 @867
 

More...

NSWorkspace launches in foreground

Okay, just in time to make another submission to Happy Apple Bug Friday (Bug #4506684): I have an application which consists of a GUI and a background daemon embedded in its bundle. Whenever you change the settings, it relaunches the daemon so it picks up its settings.

My first attempt used [[NSWorkspace sharedWorkspace] launchApplication: @"path/to.app"];. This worked fine except that every time the helper was launched, my app's front window was deactivated. Okay, so I guessed that it was launched like a GUI application and tried the showIcon: NO autolaunch: NO-variant. I tried autolaunch:YES as well, because the docs said something about daemons. No dice.

I finally resorted to LSOpenCFURLRef( (CFURLRef) [NSURL fileURLWithPath: @"path/to.app"], NULL ); and lived happily ever after.

Apparently, NSWorkspace launches all applications, even NSBGOnly and NSUIElement applications, as GUI apps, but the OS then can't activate them. What happens is that your app stays active, but its frontmost window loses focus. Very annoying to the user. To launch a daemon, you have to use Launch Services.

Reader Comments: (RSS Feed)
Nir Soffer writes:
Why not use NSTask for the background app?
Uli Kusterer writes:
Because it was a background daemon that has a GUI, and NSTask doesn't correctly launch those (at least on some MacOS X releases I had to be compatible with).
Or E-Mail Uli privately.

 
Created: 2006-04-07 @683 Last change: 2024-11-15 @664 | Home | Admin | Edit
© Copyright 2003-2024 by M. Uli Kusterer, all rights reserved.