• 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: Keith Alperin <email@hidden>
  • Date: Thu, 5 May 2005 23:00:22 -0500

Ondra, thank you for your response!

I'm trying to interact with the first responder programatically. I'm most interested in manipulating text in in the focused text field, but there may be other cases where i will want to do something to whatever control is in focus.

I hope that this is clear enough.

Thanks again,
Keith

On May 5, 2005, at 9:01 PM, Ondra Cada wrote:

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

  • Prev by Date: Re: posting message to text view from C-function
  • Next by Date: Converting old Project Builder projects?
  • Previous by thread: Re: getting the key window from another application
  • Next by thread: Re: getting the key window from another application
  • Index(es):
    • Date
    • Thread