Have you every wondered how much time do you daily spend on your computer?
You come in, set your coffee, turn on your applications, and get to work. Sadly, then you don’t know how much you’ve worked after a month. You don’t have any data or any averages.
Eureka?
This is a fun article to log some of that.
I nowhere think that the approach I’ve taken is perfect or is without errors. It works for me and this is purely for fun!
The approach I’ve taken is that I open my e-mail first thing after opening my computer and it’s the last thing I close. I’m no longer working after I close the e-mail application.
I am not choosing to this via the computer up-time or sleep/wake time becuse my behaviour w.r.t if I put my computer to sleep or powered off is not consistent.
So, here goes :-
Objective
- Calculate time spent with an application open, I’ve chosen this to be my e-mail application, but can be any.
- Log the time when the app was opened in a file (temporarily) via the system time.
- Log the time when the app is closed, co-relate the time for when the app was opened, calculate the difference.
- Upload the changes to a repository. ( You may choose, S3/DropBox etc.)
Pre-requisetes
- I haven’t checked if the OSx version is a requirement, though I reckon it shouldn’t be, I’m using High Sierra
- Python
- Access to the shell
- Machintosh
- You’ll have to interact the app (like I choose Outlook) with the method of calling our script ( details below )
Steps!
- See my code here and clone it . There are two seperate scripts, one to store the start time and the other to note the end time!
- Create a repository in github or choose whatever backup solution if you want and ghet familiar with it (from the command line)
- If you don’t want to source it, just ignore it!
- Since for this article (and my use) I’m going to upload this to a repository, consider this repository as an example.
- You’ll need a file named
usage_statistics.json
in that repository to function and the file should contain something like this when you start{"Statistics": {}}
- That is the JSON format I choose to begin with.
- That’s it ( see the details below )
Opening the App
All you need to open the file is to use Apple-Script see also osascript
Hit it like this while calling the script to note the start timne of the application
Closing the App and storing
All you need to close the file again is to use osascript.
Hit it like this
Feeling Fancy?
Automator > Create New Service > Run Shell Script and paste the two commands in there!
Maybe even load this JSON into a graphing service and create a graph!