I'm developing an commercial application that does exactly what you describe and I've been messing with different ways of doing this for over a year now. I'm a newbie developer, so I'm totally open to the idea that there may be a much better way of doing it than my way, but it seems to be stable and work.
I use Apple Script
I get the path of the active document every 3 seconds, but if the active application is the Finder, I get the path of the active window. I do this using Apple Script as described by the accepted answer.
Getting Window List using Carbon
To get the window list of all processes to get the window ID (something Apple Script can't do), I use CGWindowListCopyWindowInfo as detailed in this question:
http://stackoverflow.com/questions/311956/getting-a-unique-id-for-a-window-of-another-application
This presents me an array with all the windows of all processes ordered by which is frontmost. So all I need to do is pluck the first entry from the array. This can also be used to get a screengrab of the front window, if that's helpful to you, as shown in the Son of Grab sample application, which has been invaluable to me as a working example.
Sending Apple Script from Cocoa
When it comes to Apple Script, I've experimented with all 3 that Jim suggests and my conclusion is that each has it's issues, both in terms of stability and flexibility.
Apple Event Manager relies on you
sending raw Apple Events. For me,
this was too much like hard work and
too low level.
Using NSAppleScript I found to be
slow and error prone. It's also
pretty clumsy when you want to send a
whole variety of Apple Script
messages as I do.
When reading about Scripting Bridge,
I got very excited, only to try it
out and be very disappointed. For the
attributes of the windows I was
trying to grab, it didn't even
recognise them as existing. It seemed
to me to be buggy and weird. I expect
if the commands you're sending are
supported by SB, it would be the best
option.
A Fourth Option
I now rely on a fabulous Objective C wrapper around Apple Script called AppScript. It's been around for many, many years, it's stable, the developer is great and most of all it just works.
It has rock solid methods which allow you to send Apple Script and it'll even return errors for you neatly without a whole load of potentially buggy and messy code needing to check for them.
I've been using it for a year now with no problems. If you have any other questions about how to do this, please don't hesitate to comment and I'll try my best to answer them.