Is there any way to find out how long I've used a certain app for?

Discussion in 'Mac Basics and Help' started by bingefeller, Jun 27, 2016.

  1. bingefeller macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
    #1
    A strange request - but I'm trying to work out how long I spend with a certain app open. Is there any way that I can do this, without using a third party app?
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    You can try this :
    • Open AppleScript Editor
    • Paste in the following code. I'm using VLC as an example, make sure to replace it with the name of that certain app!
    Code:
    global startDate
    set startDate to (current date)
    tell application "VLC" to activate
    on idle
        if application "VLC" is not running then
            set stopDate to (current date)
            set timeInSec to stopDate - startDate
            set timePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & timeInSec & "))'"
            display notification "The application \"VLC\" ran for " & timePassed & " in h:mm:ss."
            tell me to quit
        end if
        return 1
    end idle
    • Make sure you save the script as a Stay-Open application (i.e., with the option to "Stay open after run handler" enabled)
     
  3. bingefeller thread starter macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
  4. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    You're welcome.
     
  5. bingefeller thread starter macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
    #5
    I hate to be a pain but, is there anyway that I will add up all the number of hours and minutes I have used the application for?

    Say I use the app for 30 minutes one day, when I quit the app the script will tell me that the app has been running for 30 minutes. Say the next day I use it for 15 minutes - can I get the script to tell me that the app has been running for a total of 45 minutes?

    Many thanks!
     
  6. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    Try this :

    Code:
    property totalTimeInSec : 0
    global startDate
    set startDate to (current date)
    tell application "VLC" to activate
    on idle
        if application "VLC" is not running then
            set stopDate to (current date)
            set timeInSec to stopDate - startDate
            set totalTimeInSec to totalTimeInSec + timeInSec
            set timePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & timeInSec & "))'"
            set totalTimePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & totalTimeInSec & "))'"
            display notification "Application \"VLC\" ran for " & timePassed & return & "Total: " & totalTimePassed
            tell me to quit
        end if
        return 1
    end idle
     
  7. bingefeller thread starter macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
    #7
    Once again, Kryten2, many thanks!
     
  8. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    No problem, glad to help. A word of caution though! The value set by a property definition is not reset each time the script is run; instead, it persists until the script is recompiled. Meaning you've been using the script for a few days and decide to change something then the value will be reset to the initial value for the property eg 0. Might I ask what app you're monitoring and do you expect the value to go beyond 24 Hours?
     
  9. bingefeller thread starter macrumors 6502

    Joined:
    Jun 25, 2007
    Location:
    Northern Ireland
    #9
    It's for Textual, an IRC app. I wont be using it for more than 24 hours.
     

Share This Page