I was afraid you were going to say Services :) When I'm using this both apps 
are under my control.

Haven't tried this, but you could try checking which app is active in 
applicationWillBecomeActive: and restore that when you're done.

----- Original Message -----
From: "Gerriet M. Denkmann" <gerr...@mdenkmann.de>
To: "Ken Thomases" <k...@codeweavers.com>
Cc: cocoa-dev@lists.apple.com
Sent: Tuesday, January 31, 2012 10:40:11 AM
Subject: Re: How to deactivate an app


On 31 Jan 2012, at 17:18, Ken Thomases wrote:

> On Jan 31, 2012, at 1:55 AM, Gerriet M. Denkmann wrote:
> 
>> I have an app A, where I can select a word and press a button.
>> This starts (or activates) another app called B, which displays some 
>> information about this word.
> 
>> But if there is no information about the word, app B should make app A 
>> active again.
>> But how?
>> (B should not be hidden; it should remain visible, so that the user sees: 
>> "Word not found".)
> 
>> There probably is a simple, direct and obvious solution. But I cannot see it.
> 
> There isn't, as far as I know.  The best general-purpose solution I'm aware 
> of is for app B to track activations of other apps using Carbon events 
> (kEventClassApplication , kEventAppFrontSwitched).  Then, use that info to 
> switch back to the last activate app.
> 
> I suppose, these days, you can also key-value observe the runningApplications 
> property of [NSWorkspace sharedWorkspace] to learn when apps come and go, and 
> then key-value observe the active property of all of the NSRunningApplication 
> objects in that collection to track which was last active.  That doesn't seem 
> like much of an improvement over the Carbon events approach, though.
> 
> However, your case seems more specific.  Are both apps A and B ones that 
> you're writing?  
Yes, they are.

> Can't you just switch back to app A directly, if it's the only thing that 
> will be invoking app B? 

> Or have I misunderstood your case (in which case, maybe you could clarify).
App B offers a service "look up word". 
And app A uses this service.

While usually it is app A which uses this service, it could be really any app 
which displays text.

Lee Ann Rucker's solution looks interesting, but would not work between any app 
and B.

Ideally the service mechanism should have an argument like "pid of sending app" 
but there is (as far as I can see) none.

Probably I have to watch for these Carbon events you have mentioned.

(Just tried these Carbon events. This is a royal pain, because of non-existence 
of any documentation.
And the switching back does not work, if A (using services) did start B. But 
this is a minor inconvenience.)


Kind regards,

Gerriet.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/lrucker%40vmware.com

This email sent to lruc...@vmware.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to