• 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: Registering for NSNotification globally?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Registering for NSNotification globally?


  • Subject: Re: Registering for NSNotification globally?
  • From: "M. Uli Kusterer" <email@hidden>
  • Date: Wed, 8 Dec 2004 08:05:16 +0100

At 20:53 Uhr -0500 07.12.2004, Lee Morgan wrote:
Is there a way that I can register my app to receive a specific notification when it is posted for _any_ other app?

In general, there isn't, as it would be a security risk. Your app could log such actions and send them over the net, or whatever.


For example, so I could register for the "NSApplicationDidBecomeActiveNotification" and have my method called whenever the user switches apps (not just to mine), and then find out the name of the newly activated app.

In this particular case, it may actually be the exception. I'm not sure anymore whether this was Carbon or Cocoa, but I think if you register for this notification and pass NIL as the object, you will even get notifications for other applications.


If that doesn't work, it definitely works in Carbon. So, you could try registering for the appropriate Carbon Event and then send a notification of your own making for the rest of your app to pick up. That's how the Moose says something when you switch between applications.

I haven't tried getting the application's name, but it should be possible. At worst, you should be able to get a PSN or PID for the process with the notification/event, which you would then pass to the appropriate API to get more information.

As a final refuge, you could also poll. I think NSWorkspace contains a method to get an info dictionary for all running apps and the active app. If "active" means "frontmost", and not "the one currently executing" (the latter would always be yours), you could probably compare the two and find out that way.
--
Cheers,
M. Uli Kusterer
------------------------------------------------------------
"The Witnesses of TeachText are everywhere..."
http://www.zathras.de
_______________________________________________
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: Registering for NSNotification globally?
      • From: Peter Maurer <email@hidden>
References: 
 >Registering for NSNotification globally? (From: Lee Morgan <email@hidden>)

  • Prev by Date: Re: sorting on floats
  • Next by Date: Re: Object-C question #1
  • Previous by thread: Re: Registering for NSNotification globally?
  • Next by thread: Re: Registering for NSNotification globally?
  • Index(es):
    • Date
    • Thread