• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: launchApplication and window deselection
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: launchApplication and window deselection


  • Subject: Re: launchApplication and window deselection
  • From: email@hidden
  • Date: Wed, 27 Feb 2002 16:42:16 -0800

I'm working on an app that sometimes launches a background application.
This background application sets LSUIElement to 1 so that it doesn't
show up in the dock and it has no UI.

I use the following code to launch the app (it lives inside my main
app's bundle):

helperPath = [[NSBundle mainBundle] pathForResource:helperAppNameShort
ofType:@"app"];
[[NSWorkspace sharedWorkspace] launchApplication: helperPath];

This works well enough, but my main app's main window becomes deselected
afterwards. Also the menu bar is deselected - I click on the menu bar
and it's "dead" - no menus drop down. Once I click on the main window,
it becomes selected and menus work again.

Well, in NSWorkspace's doc I find launchApplication:showIcon:autolaunch:, which says, among other things, "If autolaunch is YES, the autolaunch default will be set as though the application were autolaunched at startup. This method is provided to enable daemon-like applications that lack a normal user interface. Its use is not generally encouraged." This doc is unclear as to what this parameter actually *does*, but you might try it, it sounds like it might be applicable.
The NSWorkspace method openFile:withApplication:andDeactivate: also looks interesting, because it has that "andDeactivate:" parameter. You might try supplying your application's path as both the file and the application path, or some such, and see whether it will launch your app for you.

This seems like a bug (which I'll report if it is) and I'm trying to
come up with a work around. I tried immediately calling

[mainWindow makeKeyAndOrderFront: nil];
[mainWindow makeFirstResponder:mainWindowView];

after the launchApplication method is invoked, but that doesn't help.

The problem is what app is considered active, not what window is key. Try [NSApp activateIgnoringOtherApps:YES];. You might be able to do this synchronously, or you might have to wait until you receive the NSWorkspaceDidLaunchApplicationNotification.

Ben Haller
Stick Software
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: launchApplication and window deselection
      • From: Michael Peirce <email@hidden>
  • Prev by Date: Re: Another filesystem mystery
  • Next by Date: Re: Option key or Alternate key
  • Previous by thread: Re: launchApplication and window deselection
  • Next by thread: Re: launchApplication and window deselection
  • Index(es):
    • Date
    • Thread