Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way I can get total listening time from command line? I want to write a script to keep track of how much time I spend listening to music on a daily basis.

share|improve this question
    
What I ended up writing: github.com/deadghost/banshee-listening-time. It's not super pretty but it works. It's inspired by how John Carmack listens to music whenever he's productive and checks how much music he listened to at the end of the day. –  deadghost Mar 10 at 17:56

2 Answers 2

up vote 6 down vote accepted

First, using the following command:

pgrep banshee

you can check if Banshee is running.

If yes, you can use:

banshee --query-current-state

command in your bash script to get the current Banshee state (if it's playing or not).

Here is some rudimentary bash code from which you can start and improve your script:

#!/bin/bash

seconds=0

while : ; do
    if ( pgrep banshee > /dev/null ); then
        if [ "$(banshee --query-current-state | cut -d' ' -f2)" = "playing" ]; then
            (( seconds++ ))
            echo "Total listening time: $seconds seconds"
        fi
    fi
    sleep 1
done
share|improve this answer
2  
fantastic addition on "How to". +1 from me. –  souravc Mar 8 at 16:27
    
I ended up keeping track of time using unix time since sleep 1 is 1 second plus the time it takes to execute the body of the while loop. –  deadghost Mar 10 at 18:05

Here are some (not console, but with GUI) time-tracking apps:

GTimer:

  • Package: gtimer
  • Section: universe/utils
  • Description:

    GTK-based X11 task timer
    

    A graphical program that tracks how your time is spent. Maintains a simple list of tasks, each of which can belong to a project, and allows you to track time in each. Multiple clocks can run simultaneously, annotations can be added to a day's time, and reports can be generated in either HTML or text. If GTimer detects that you're idle, you are given the option of subtracting off the time you spent idle when you return.

    Compared to other time tracking applications, GTimer is graphical without depending on a desktop environment and aims for simplicity rather than attempting to be a full-fledged project tracking and billing application.

  • Snapshot:

    snap_gtimer

  • Homepage

  • Installation:

    sudo apt-get install gtimer
    

GTimeLog:

  • Package: gtimelog

  • Section: universe/admin

  • Description:

    A Gtk+ time tracking application
    

    Time Tracker (a.k.a. gtimelog) provides a time tracking application to allow the user to track what they work on during the day and how long they spend doing it.

  • Snapshot:

    shap1

  • Homepage

  • Installation:

    sudo apt-get install gtimelog
    

Time Tracker:

  • Package: hamster-applet
  • Section: universe/gnome
  • Description:

    Time tracking applet for GNOME
    

    Project Hamster helps you to keep track of how much time you spend on various activities during the day. Whenever you move from one task to another, you change your current activity in the GNOME applet.

    It can present graphical statistics of how long you have spent on each task, and may be useful for project management or keeping employee timesheets.

  • Snapshot:

    snap2

  • Homepage

  • Installation:

    sudo apt-get install hamster-applet
    

    To install AppIndicator for the same:

    sudo apt-get install hamster-indicator
    
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.