Xfce Forum

Sub domains
 

You are not logged in.

#1 2021-04-11 02:43:47

sonycdr
Member
Registered: 2009-01-30
Posts: 130

Help me to fix a genmon script

I'm using a openbox system with a tint2 panel. In this panel I had a little 'executor' to show me the info about audio tracks: author and song's name.

The executor shows the output of playerctl. Well, the command in tint2 is this:

{ echo "$(playerctl metadata artist | awk '{print "♫ " $0 ""}')"; echo - "$(playerctl metadata title | awk -v len=48 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }')"; } | tr "\n" " "

I want charge this command on a genmon instance in my xfce panel, so I create a bash script but don't works:

#!/usr/bin/env bash

{ echo "$(playerctl metadata artist | awk '{print "♫ " $0 ""}')"; echo - "$(playerctl metadata title | awk -v len=48 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }')"; } | tr "\n" " "

                                           

In genmon I set the name of the script file that is a executable file, this file is in my binaries' path and works when I call it from the terminal.

Please, has anyone a tip for to achieve that this command works?

Last edited by sonycdr (2021-04-11 02:46:22)

Offline

#2 2021-04-11 05:27:37

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,948

Re: Help me to fix a genmon script

Your script works fine for me. What version of the genmon plugin are you using?

Maybe try this version instead - it might work better:

#!/usr/bin/env bash

echo "$(playerctl metadata artist | awk '{print "♫ " $0 ""}') - $(playerctl metadata title | awk -v len=48 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }')" | tr "\n" " "

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2021-04-11 23:09:24

sonycdr
Member
Registered: 2009-01-30
Posts: 130

Re: Help me to fix a genmon script

ToZ thank you for your attention. I've achieved make run the script in my genmon instance, but I need clarify some issues.

Firstly the OS specs:

OS: Debian 10
genmon: 4.0.1-2

Well, I create the bash script (eg. MUSIC) in my local folder for binaries, this folder is added in my $PATH so when I call to the script on terminal it works. Don't forget that this bash script is executable (chmod +x MUSIC). Then I create the instance of genmon and type in the order's place MUSIC, but genmon can't read it.

But this words made me think:

ToZ wrote:

Your script works fine for me ....

So in genmon I change the command:

Before: MUSIC
After:  /home/userpc/.local/bin/MUSIC

Now, the script works but I have a question: Is necessary in genmon type the whole path of the script when it is in local folder?

PS: This script is very simple, but is powerful. In tint2 I can use mouse actions over the plugin, I don't know is possible to achieve the same behavior with xfce panel and genmon plugin, but playerctl/tint2 let me play, pause or change song with clics. How to use clic events with genmon plugin for pause/play music or active other playerctl feature?

Offline

#4 2021-04-12 00:40:25

CwF
Member
Registered: 2018-01-28
Posts: 287

Re: Help me to fix a genmon script

for Debian /usr/local/bin is usually first in the path. It requires root to place your script, but I'm in the habit of placing them there and calling them MUSIC.genmon. So in the genmon config the command is simply music.genmon. Yes, I'd lower case the name, personally. This also puts this in place for other users, if helpful. Any reference in the script can be ~/ for all users.

Offline

#5 2021-04-12 03:41:30

sonycdr
Member
Registered: 2009-01-30
Posts: 130

Re: Help me to fix a genmon script

CwF, I type MUSIC in uppercase only here for a didactic purpose. My original file is in lowercase, but I have this file without extension:

My file: music
Your file: music.genmon

But with extension .genmon the script don't work.

Your other advice don't work for me too, when I type ~/.local/bin/music, genmon can't read the script.

Offline

#6 2021-04-12 14:16:18

CwF
Member
Registered: 2018-01-28
Posts: 287

Re: Help me to fix a genmon script

sonycdr wrote:

when I type ~/.local/bin/music, genmon can't read the script.

I mean /usr/local/bin/music.genmon  not ~/usr/bin. Check your path for /usr/local/bin. That is root area not within home.

I mention ~/ within the script to reference data with home if so. The script in global /usr/local/bin then works for all users but may access data within a user's home, then the ~/ reference.

Only the panel genmon uses music.genmon.  So music.genmon is not useful on the cli. the genmon 'contains' the script for genmon purpose, not in cli executable form, yes?

something like;

echo -e "<txtclick>your script</txtclick>"

Offline

#7 2021-04-15 10:32:34

Misko_2083
Member
Registered: 2015-10-13
Posts: 191
Website

Re: Help me to fix a genmon script

sonycdr wrote:

CwF, I type MUSIC in uppercase only here for a didactic purpose. My original file is in lowercase, but I have this file without extension:

My file: music
Your file: music.genmon

But with extension .genmon the script don't work.

Your other advice don't work for me too, when I type ~/.local/bin/music, genmon can't read the script.

Maybe you need to tell genmon to use the shell.
The command for Genmon

/usr/bin/env bash -c "~/.local/bin/music"

in the script genmon calls, you tell genmon what text to display <txt>text</txt> which script launch on click <txtclick>bash -c script</txtclick>
As for using  playerctl you can do a bit of scripting and yad as the UI.

~/.local/bin/music

#!/usr/bin/env bash
# Note: best to set the monospace font for this genmon

vol="$(/usr/bin/amixer get Master | /usr/bin/grep "\[on\]" | /usr/bin/sed 's/[][%]//g')"
vol=( $vol )

# check if pulseaudio is running, set CURVOL accordingly.
[ $(pidof pulseaudio) ] && CURVOL="${vol[4]}"
[ $(pidof pulseaudio) ] || CURVOL="${vol[3]}"

  function _pbar {
    let _progress=(${1}*100/${2}*100)/100
    let _done=(${_progress})/10
    let _left=10-$_done
    _fill="$(printf "%${_done}s")"
    _empty="$(printf "%${_left}s")"
    printf "<txt>%s[%3d%%]%s</txt>" "${_fill// /▇}" "${_progress}" "${_empty// /▇}"
  }
_end=100

_pbar ${CURVOL} ${_end}

# here you call yad UI when the genmon is clicked
echo "<txtclick>/usr/bin/env bash -c \"~/.local/bin/yad_genmon_audio.sh\"</txtclick>"

~/.local/bin/yad_genmon_audio.sh

#!/usr/bin/env bash

if [ -z `which xdotool` ]; then
	msg="  Package 'xdotool' is not installed, please install it. "
	$MESSAGE  "`echo -e $msg`" 
       exit
fi

if [ -z `which amixer` ]; then
	msg="  Could not find amixer, setting volume will not be possible. \n Please install 'alsa-utils' to make it work "
	$MESSAGE  "`echo -e $msg`"
        exit
fi

VERSION=`yad --version | awk '{ print $1 }'`
verlte() {
    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}

verlt() {
    [ "$1" = "$2" ] && return 1 || verlte $1 $2
}

if verlt $VERSION 0.37.0; then
yad --text=" The version of yad installed is too old for to run this program,  \n Please upgrade yad to a version higher than 0.36   " --button="gtk-close"
exit
fi

height=300 # set dialog height
splitter=150 # set paned dialog splitter

yad_alsa_audio(){
 # set window class
 YAD_CLASS="YAD_GENMON_AUDIO"

 # Unmap the window if the script is relaunched

   pids="$(xdotool search --class "$YAD_CLASS")"
   wpid="$(xdotool getwindowfocus)"

   for pid in $pids; do
        # Compares window class pid with the pid of a window in focus
        if [[ "$pid" == "$wpid" ]]; then
           xdotool windowunmap $pid
           exit 1
        fi
   done


vol=$(amixer get Master | grep "\[on\]" | sed 's/[][%]//g')
vol=( $vol )
# CURVOL=$(echo ${vol[4]} | sed 's/[][%]//g')
# fredx181, check if pulseaudio is running, set CURVOL accordingly.
[ $(pidof pulseaudio) ] && CURVOL="${vol[4]}"
[ $(pidof pulseaudio) ]  || CURVOL="${vol[3]}"

eval $(xdotool getmouselocation --shell)

X=$(($X-125))
Y=$(($Y-height))

KEY=$(echo ${RANDOM})

while true; do
echo "Status: $(playerctl status)"
echo "$(playerctl metadata artist | awk '{print "♫ " $0 ""}') - $(playerctl metadata title | awk -v len=48 '{ if (length($0) > len) print substr($0, 1, len-3) "..."; else print; }'  | tr "\n" " ")" 
sleep 1; done |
yad --plug=$KEY \
    --tabnum=1 \
    --form \
    --cycle-read \
    --field="" \
    --field="":TXT &

yad --tabnum=2 \
    --plug=$KEY \
    --scale \
    --print-partial \
    --width=300  \
    --min-value=0 --max-value=100 \
    --borders="12" \
    --value="$CURVOL" 2> /dev/null | \
while read VOL; do
    /usr/bin/amixer sset 'Master' "$VOL%"
done &
yad --paned \
    --class="$YAD_CLASS" \
    --key=$KEY \
    --height=$height \
    --splitter=$splitter \
    --posy=$Y --posx=$X \
    --undecorated \
    --close-on-unfocus \
    --on-top \
    --skip-taskbar \
    --mouse \
    --sticky \
    --tab="Tab 1" --tab="Tab 2" \
    --button="Prev":'sh -c "playerctl previous"' \
    --button="Next":'sh -c "playerctl next"' \
    --button="$(echo -e "\xe2\x8f\xaf")":'sh -c "playerctl play-pause"'

}
export -f  yad_alsa_audio

yad_alsa_audio

yad_genmon_audio.sh requires yad, xdotool and alsa-utils
This yad dialog uses sets the global alsa volume, because I feel lazy and only recycled some lines from the other scripts.
With a little scripting you can use the progress bar to set the volume with playerctl.

kX8dhG7.gif

Last edited by Misko_2083 (2021-04-15 10:52:58)


Do you want to exit the Circus?
https://www.youtube.com/watch?v=ZJwQicZHp_c

Offline

Board footer

Powered by FluxBB