Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > listening to Apple Events

listening to Apple Events
Thread Tools
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Aug 10, 2002, 08:01 AM
 
How to I listen to Apple events?

It would be a good start if you can tell me how to do it directly in AppleScript, but even better if you would tell me how I could (later) do it in Objective C.

I would like to listen to "sleep", "print", etc.
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Aug 10, 2002, 11:48 AM
 
In Cocoa, it's all about Notifications. In Carbon... I'm not so sure. Applescript, unfortunately, I have no clue.

I'll extend the question: how can I catch events in Carbon? Does it require polling, or can I do something like [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomething... (obviously syntax like this doesn't work, but is there a function in Carbon that results in the same type of thing?)

Just wondering, needing to catch mouse-moved events while in a menu, and the setup of Carbon is quite a bit different that Cocoa (Objects vs procedural, right?)

Matt Fahrenbacher
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Aug 10, 2002, 11:50 AM
 
Originally posted by Ghoser777:
In Cocoa, it's all about Notifications. In Carbon... I'm not so sure. Applescript, unfortunately, I have no clue.

I'll extend the question: how can I catch events in Carbon? Does it require polling, or can I do something like [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doSomething... (obviously syntax like this doesn't work, but is there a function in Carbon that results in the same type of thing?)

Just wondering, needing to catch mouse-moved events while in a menu, and the setup of Carbon is quite a bit different that Cocoa (Objects vs procedural, right?)

Matt Fahrenbacher
So, how you do it in cocoa?
     
Professional Poster
Join Date: Dec 2000
Location: Chicago, Illinois
Status: Offline
Reply With Quote
Aug 11, 2002, 03:03 PM
 
Originally posted by VEGAN:


So, how you do it in cocoa?
Obj-C or Java? Just so I know what sample code to post.

Without code, what you'll need to do is use NSNotificationCenter and NSNotification. Reading the info about them in the Foundation reference documentation will help explain mostly how it works.

Essentially, there are certain events (like power off) which the operating system will post to the default notification center. If you so choose, you can set one of your objects to listen for those notifications and respond to them when they are received. You can even create your own notifications and post them so objects without references to each other can communicate (that's how some System Preference Panes communicate with the related application, like say the Dock).

Matt Fahrenbacher
     
Mac Elite
Join Date: Feb 2001
Location: Vancouver, WA
Status: Offline
Reply With Quote
Aug 12, 2002, 01:42 PM
 
NSNotification != AppleEvents.

See Foundation/NSAppleEventManager.h for the low-level interface for creating AppleEvent handlers. But you don't need to do that, really: it's a lot easier to use the higher-level AppleEvent/AppleScript interface for Cocoa. See http://developer.apple.com/techpubs/...ity/index.html for more.
Rick Roe
icons.cx | weblog
     
VEGAN  (op)
Senior User
Join Date: Jun 2002
Location: UK
Status: Offline
Reply With Quote
Aug 14, 2002, 09:40 AM
 
Originally posted by Ghoser777:


Obj-C or Java? Just so I know what sample code to post.

Without code, what you'll need to do is use NSNotificationCenter and NSNotification. Reading the info about them in the Foundation reference documentation will help explain mostly how it works.

Essentially, there are certain events (like power off) which the operating system will post to the default notification center. If you so choose, you can set one of your objects to listen for those notifications and respond to them when they are received. You can even create your own notifications and post them so objects without references to each other can communicate (that's how some System Preference Panes communicate with the related application, like say the Dock).

Matt Fahrenbacher
Obj-C please
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 06:09 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2