You are not logged in.
For the last couple of days I've been trying to write a perl script to display my Clementine output in Conky. Perl being the only programming language I know even a little bit about (although still pretty limited). My script didn't work. It pretty much displayed everything that was happening with Clementine except for what I wanted... I gave up on that, but I found a pre-made bash script while searching online that actually works and is more or less exactly what I wanted in the first place (thank you google search). It displays the currently playing track along side the artist, but I would like to add a second line that displays the album and if clementine is not playing I would like it to display "Not playing" so there isn't just a blank space at the bottom of my conky. My knowledge of bash scripting is pretty much nonexistent. It's always been something I've wanted to learn but never found the time to do it due to things like work, girlfriend and drinking taking up most of my time ![]()
Anyway, here's the script I found:
#!/bin/bash
TRACK=`qdbus org.mpris.clementine /TrackList \
org.freedesktop.MediaPlayer.GetCurrentTrack`
qdbus org.mpris.clementine /TrackList \
org.freedesktop.MediaPlayer.GetMetadata $TRACK \
| sort -r | egrep "^(title:|artist:)" | sed -e "s/^.*: //g" \
| sed -e ':a;N;$!ba;s/\n/ - /g' | head -c 36Any help with this would be greatly appreciated.
Oh yeah, If anyone else wants to use this script, first make it executable by running the chmod command and add this line to your conkyrc:
${execi 10 /path/to/script_name}EDIT: I put this in the wrong forum... My apologies.
Last edited by Mr_ED-horsey (2011-11-16 17:12:04)
Desktop: Fedora 21 Mate + Compiz [x86_64] on 2 TiB HDD / Windows 7 Professional [x86_64] on 500 GiB HDD
Laptop: Arch Linux + Openbox [i686] 120 GiB SSD on Acer c720 Chromebook
Offline
Moving to Programming & Scripting.
To know or not to know ...
... the questions remain forever.
Offline
Ok... Maybe I should try a different tactic ![]()
I know what the grep, sed & head commands do , but how does the 'e' in front of grep change the command? And I'm still confused about the variables after the sed command. Mainly these:
"s/^.*: //g" \':a;N;$!ba;s/\n/ - /g'The 'man sed' page doesn't really have any information on those.
Desktop: Fedora 21 Mate + Compiz [x86_64] on 2 TiB HDD / Windows 7 Professional [x86_64] on 500 GiB HDD
Laptop: Arch Linux + Openbox [i686] 120 GiB SSD on Acer c720 Chromebook
Offline
The 'e' in egrep means to use extended regular expressions. It is the same as grep -E. The reason for there being a difference between a 'regular expression' and an 'extended regular expression', is that 'regular expressions' came first. Later, people came up with a more powerful set of expressions that weren't always compatible with the original. Thus you had to use the -E flag with grep when you wanted to use 'extended'.
Extended vs. regular only applies to Posix, such as grep and sed. Perl and other languages define their own set of regex's and won't necessarily have the concept of extended regex's.
's/^.*: //g' means to remove everything up to and including the space immediately following the last ':' on the line.
My sed fu isn't that great, but I believe that
':a;N;!ba;s/\n/ - /g'means to concatenate two adjacent lines, separated by " - ".
Offline