• 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
[NSApp targetForAction:] returns nil from Services menu handler when app not active
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[NSApp targetForAction:] returns nil from Services menu handler when app not active


  • Subject: [NSApp targetForAction:] returns nil from Services menu handler when app not active
  • From: Philip Dow <email@hidden>
  • Date: Thu, 16 Nov 2006 11:07:54 +0100

I've run into a problem where both NSApp's targetForAction: and targetForAction:to:from: return nil when called from a Services menu handler. The handler is properly installed at launch and I can verify that the method is being called when my application's service is selected from the services menu.

The issue seems to be NSApp returning nil for both mainWindow and keyWindow. For example, in the following code, "target" is always nil:

id target;
NSWindowController *keyWindowController = [[NSApp keyWindow] windowController];
NSWindowController *mainWindowController = [[NSApp mainWindow] windowController];

if ( [keyWindowController respondsToSelector:@selector (servicesMenuAppendSelection:desiredType:)] )
target = keyWindowController;
else if ( [mainWindowController respondsToSelector:@selector (servicesMenuAppendSelection:desiredType:)] )
target = mainWindowController;
else
target = [NSApp targetForAction:@selector (servicesMenuAppendSelection:desiredType:) to:nil from:self];


I suppose this is the case because the main and key windows belong to another application when mine is not active. How then can I best get the intended target of the services command? It should be going to the frontmost window in my application that can handle it.

I've tried grabbing a list of the application's windows and iterating through them until I find one whose delegate responds to the method. But it may be the case that two document windows which both respond are onscreen. Iterating through the window list does not necessarily give me the frontmost window.

Has anyone else encountered a problem like this? Is there a workaround?

-Phil

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: NSString comparison with locale single character error
  • Next by Date: Re: CoreData, reset a persistent store
  • Previous by thread: Re: Your details [:.VIRUS.:]
  • Next by thread: Diggest [:.VIRUS.:]
  • Index(es):
    • Date
    • Thread