Need help writing automatic time-tracking app

Discussion in 'Mac Programming' started by Jackb602, Jun 8, 2005.

  1. Jackb602 macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #1
    I know close to nothing about programming, but I'm looking for help on writing what I think would be a very basic program or script. I'd like the program to simply keep track of how long a given application is active. For example, let's say I have Word, Mail, and Photoshop open and I'm using Mail at the moment. The app would start a timer as soon as I open or switch to mail. When I switch to Word, the Mail timer would stop and a Word timer would start. At the end of the day, the app could display a simple report showing how much time I spent in each app. Of course, all of this would happen automatically in the background so I wouldn't have to constantly be keeping track of time.

    Is this something that could easily be done in AppleScript or is it not as simple as I think it is? I wouldn't mind taking it on as a learning project, but if it's beyond my abilities, I'd consider hiring someone to write it. How difficult does this sound, and where would you recommend I start to learn more about how to accomplish this? I'd appreciate any thoughts.

    Thanks,
    Jack

    p.s. I have tried a demo of TaskCapture, but it only seems to work with certain apps.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    I'm not sure you can do this with AppleScript. I think you might be able to register for a notification from the system when the key app changes in Cocoa. Timers are inefficiant. Simply recored each time the key app changes then add up the time differences at the end of the day. I'll see if I can find out about the system notifications. If it looks easy I might be able to knock something up in a couple of days...
     
  3. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #3
    CocoaDev Discussion

    Looks pretty easy. Give me a couple of days to get something hacked together (in my spare time). I'll release as a GPL app. Sound OK?
     
  4. Jackb602 thread starter macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #4
    Robbie,

    Thanks, that would be brilliant! If you release it under GPL, that means the source code is publicly available right? That would be an interesting way for me to learn a bit about what the program does. Thanks so much for your help!

    Jack
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    Yes, releasing under the GPL means that the source code is publicly available and anyone can alter it. I'm probably not going to get much done on this tonight as it's 11pm already and I've been having a BBQ in a park and drinking a few beers :)
     
  6. Jackb602 thread starter macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #6
    Cool, that will be a good way for me to get my feet wet and see how it's organized. One other feature that I thought would be useful is for the app to recognize when the machine has been idle for a while (i.e. no keyboard or mouse input) and stop all timers until the user returns. How hard would that be? Thanks again for helping out with this. No rush of course; enjoy the cookout!

    Jack
     
  7. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #7
    Jack,

    I've just checked out your profile. Are you seriously on a very old Mac? All the code I write is Cocoa and in general targets the latest and latest-1 versions of OSX. So I'm talking about 10.4 and 10.3 at the moment.

    What OS are you running?
     
  8. Jackb602 thread starter macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #8

    Funny, I did used to use an 8600, but that was a long time ago. I hadn't even looked at my profile. I'm running OS X 10.3.9 on a Dual 1GHz G4. Not the fastest machine out there, but it does the job.

    Thanks,
    Jack
     
  9. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #9
    OK cool. Hopefully I'll have a basic demo running later today. I was building for 10.4 using the Universal SDK (PowerPC & Intel) but I'll switch that to 10.3 (no great loss right now).
     
  10. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #10
    TimeWaster 0.0.0

    This is mostly just a work in progress. It will improve! But the basic functionality works (check the Window Menu).

    Edit to add: The name is not meant to imply anything about the original poster! It just seemed like a snappy and appropriate name. Honest!
     
  11. Jackb602 thread starter macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #11

    Hey, I like the name! It cracked me up. I've just downloaded it and I'll take a look at it. Thanks again for your help!

    Jack
     
  12. Jackb602 thread starter macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #12
    Robbie,

    I've installed TimeWaster and set it as a Startup Item. I then quit all my apps, logged out and back in. But the two windows don't show anything. Is there anything else I should be doing?

    Thanks,
    Jack
     
  13. takao macrumors 68040

    takao

    Joined:
    Dec 25, 2003
    Location:
    Dornbirn (Austria)
    #13
    same here neither window shows anything ...

    did it work on yours robbie ?
     
  14. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #14
    The windows won't show anything till you switch to another app (i.e. not TimeWaster). for the first time. It works fine on my machine (OSX 10.4.1).

    Are you both on 10.3.9? It is possible that the Carbon calls to get the app get notified on application switching don't work on older OS versions (although the reason I went with these is that they are documented and the only Cocoa way is undocumented and does not work on 10.4).

    I did notice that it did not catch Dashboard being activated.
     
  15. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #15
    I have attached a screenshot of it on my machine.
     

    Attached Files:

  16. Jackb602 thread starter macrumors newbie

    Joined:
    Jul 23, 2002
    Location:
    Chicago
    #16
    That looks great. I'm running 10.3.9 here.

    Jack
     
  17. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #17
    Total bummer. I've just copied the built app to my Mac Mini (which is still on 10.3.9 as I've not got round to upgrading it yet) and it didn't work :( Looks like I need to use different methods to trap the events on different operating systems.

    I'll look into it over the next day or two and post back once there is a version that works on 10.3.9 and 10.4.1.
     
  18. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #18
    New version posted (at same URL as above). It works for me on 10.3.9 and 10.4.1 :)

    Yay!

    Note that I did not bump the version number and that the Timeline window is now there but the custom view does not do anything. Take this as a feature to come!
     
  19. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #19
    TimeWaster has gone 0.1.0 (initial release). Product page here. Listing submitted to VersionTracker. There are still bugs and unimplemented features (as noted in the bug list in the app). I will be updating this app over time as I fix the bugs an implement the missing features.
     

Share This Page