 |
 |
listening to Apple Events
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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
|
|
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
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Jun 2002
Location: UK
Status:
Offline
|
|
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
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|