I want to track the length of time and time of day I spend in a certain app on my laptop (it's a writing app and I want to track how much time I spend writing).

I was thinking of writing a simple script that records whenever that particular app opens and closes and exports the data to a text file.

Does anyone know where I could get started writing this. I've done a little bit of bash scripting before, but not enough to know where to start. Or if you have any better ideas on how to record this data I'd love to hear them.