Detect when application become active

I have been writing an application that takes a list of documents from another application. At the moment it collects that list in the applicationWillFinishLaunching_ section.

Is it possible to detect when my application becomes active and then run my handler to get the list of documents? I would like to do this so that if the user returns to the other application and opens or closes documents, the changes are reflected in my app.

Model: MacBook Pro 2.7 GHz Core i7 16GB RAM
Browser: Safari 537.31
Operating System: Mac OS X (10.8)

You need to register as an observer of NSWorkspace’s shared workspace’s notification centre’s NSWorkspaceDidActivateApplicationNotification notification. the handler you register will then get a notification whenever any application becomes active.

The’s a good example project in chapter 19 of my book.

Thanks Shane “ I should have looked there first!