• 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: getting the key window from another application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getting the key window from another application


  • Subject: Re: getting the key window from another application
  • From: Ondra Cada <email@hidden>
  • Date: Fri, 6 May 2005 04:01:47 +0200

Keith,

On 6.5.2005, at 3:41, Keith Alperin wrote:

Howdy. I'm trying to determine what the key window is from within a background process. I've looked into [[NSWorkspace sharedWorkspace] activeApplication], but that only gives me the process id. I've been unable to figure out how to get an NSApplication from the process id which would in turn enable me to get the key window. I found some posts about this in the cocoabuilder archives, but no definitive answers.

That's since there is no definitive answer at all :)

What do you need this for? That's the question.

Your best bet probably is AppleScript: nearly all Cocoa applications conform to it quite well, and a considerable number of other ones do, too. What you probably want is something roughly like

NSString *ass=[NSString stringWithFormat:@"tell application \"%@ \"\nget name of front document\nend tell",path];
NSDictionary *err=nil;
NSAppleEventDescriptor *ad=[[[[NSAppleScript alloc] initWithSource:ass] autorelease] executeAndReturnError:&err];
if (ad) NSLog(@"path ok: (%@)",[ad stringValue]);
else NSLog(@"path err %@",[err objectForKey:@"NSAppleScriptErrorBriefMessage"]);


There are other ways, but -- at least without knowing your real goal -- they do not seem to fit too well.

Note: far as I can say, there is absolutely no way which would work always, with any application, without an exception. Far as I know, what you can get is a near-to-perfect solution, but not a perfect one.
---
Ondra Čada
OCSoftware: email@hidden http://www.ocs.cz
private email@hidden http://www.ocs.cz/oc



_______________________________________________ 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
  • Follow-Ups:
    • Re: getting the key window from another application
      • From: Keith Alperin <email@hidden>
References: 
 >getting the key window from another application (From: Keith Alperin <email@hidden>)

  • Prev by Date: getting the key window from another application
  • Next by Date: Re: programmaticaly modify .nib files
  • Previous by thread: getting the key window from another application
  • Next by thread: Re: getting the key window from another application
  • Index(es):
    • Date
    • Thread