Sunday, May 5, 2024
6
rated 0 times [  6] [ 0]  / answers: 1 / hits: 429  / 1 Year ago, wed, may 24, 2023, 10:04:54

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.


More From » command-line

 Answers
2

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

[#26629] Thursday, May 25, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
errettas

Total Points: 160
Total Questions: 118
Total Answers: 91

Location: Laos
Member since Fri, Sep 11, 2020
4 Years ago
;