Tracking frontmost App

  • Are there any (Preferably Cocoa) api that allows an application to be
    notified whenever
    the frontmost App changes (for example from XCode to Interface Builder).
    I want this in order to implement a time tracking application.

    ------------------------------------------------------
    "Home is not where you are born, but where your heart finds peace" -
    Tommy Nordgren, "The dying old crone"
    <tommy.nordgren...>
  • On 10/13/06, Tommy Nordgren <tommy.nordgren...> wrote:
    > Are there any (Preferably Cocoa) api that allows an application to be
    > notified whenever
    > the frontmost App changes (for example from XCode to Interface Builder).
    > I want this in order to implement a time tracking application.

    I've accomplished this with a combination of the Accessibility APIs
    and NSWorkspace notifications. The process was much like this:
    1. On application start find all running applications and register for
    their "application activated" events using the accessibility API.
    2. Register a class to respond to the NSWorkspace "application
    launched" and "application terminated" notifications. On launch add
    the application to the list of applications my application is
    monitoring using the Accessibility APIs. On terminate, remove the
    application.

    This worked OK. While I ended up using a different solution for my
    purposes I managed to track application activations OK. There was some
    confusion on whether a launched application should be treated as also
    an application activated event; The app wouldn't necessarily receive
    and activation event for the application that notified my app of it's
    launch.

    I just found this tech note: http://developer.apple.com/technotes/tn/tn2050.html
    Which describes a method of monitoring application lifetimes in better
    detail than I just did.

    --
    -Corey O'Connor
  • On Fri, 13 Oct 2006 19:30:08 +0200, Tommy Nordgren
    <tommy.nordgren...> said:
    > Are there any (Preferably Cocoa) api that allows an application to be
    > notified whenever
    > the frontmost App changes

    I do it with Carbon Events. Works great (download my MothersHelper app if
    you'd like to see this in action - in fact, keeping track of what app is
    frontmost is basically *all* it does!).

    m.

    --
    matt neuburg, phd = <matt...>, <http://www.tidbits.com/matt/>
    A fool + a tool + an autorelease pool = cool!
    AppleScript: the Definitive Guide - Second Edition!
    <http://www.amazon.com/gp/product/0596102119>
  • I also use Carbon Events and, along the same lines as what Tommy is
    suggesting, track time spent in each app. Here is the source code and
    executable for my last entry to the Iron Coder contest:

    http://ironcoder.org/entries/ironcoder_2/DCJ-WHYDFML.zip

    "What Have You Done For Me Lately"

    It shows the apps you've visited lately in a bar-graph chart form.

    Daniel

    On Oct 14, 2006, at 2:37 PM, Matt Neuburg wrote:

    > I do it with Carbon Events. Works great (download my MothersHelper
    > app if
    > you'd like to see this in action - in fact, keeping track of what
    > app is
    > frontmost is basically *all* it does!).
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today