Xfce Forum

Sub domains
 

You are not logged in.

#1 2019-09-08 11:54:06

spnzdg
Member
From: Amsterdam
Registered: 2019-08-29
Posts: 23

xfce4-panel-genmon: how to change random png to sequence ???

Hello

i have a question about a genmon script for the xfce4-panel.

There is a fun script with a  random dice.
I want to make a little animated button, but in order.

This is my first time edit a script.

This is the original script :

#!/usr/bin/env bash
# Dependencies: bash>=3.2, coreutils, file

# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Optional icon to display before the text
# Insert the absolute path of the icon
# Recommended size is 24x24 px
declare -r ICON_ARRAY=(
  "${DIR}/icons/others/dice-1.png"
  "${DIR}/icons/others/dice-2.png"
  "${DIR}/icons/others/dice-3.png"
  "${DIR}/icons/others/dice-4.png"
  "${DIR}/icons/others/dice-5.png"
  "${DIR}/icons/others/dice-6.png"
)

# Compute random die
DIE=$(( RANDOM % 6 ))


# Panel
if [[ $(file -b "${ICON_ARRAY[DIE]}") =~ PNG|SVG ]]; then
  INFO="<img>${ICON_ARRAY[DIE]}</img>"
  INFO+="<click>app</click>"
else
  INFO+="<click>app</click>"
fi

# Tooltip
MORE_INFO="<tool>"
MORE_INFO+="$(( DIE + 1 ))"
MORE_INFO+="</tool>"

# Panel Print
echo -e "${INFO}"

# Tooltip Print
echo -e "${MORE_INFO}"



Thanks

Offline

#2 2019-09-08 15:12:03

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 11,485

Re: xfce4-panel-genmon: how to change random png to sequence ???

Hello and welcome.

Thanks for the Sunday morning challenge. How about the following:

Main script (gdie)

#!/usr/bin/env bash
# Dependencies: bash>=3.2, coreutils, file

# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Optional icon to display before the text
# Insert the absolute path of the icon
# Recommended size is 24x24 px
declare -r ICON_ARRAY=(
  "${DIR}/icons/dice-1.png"
  "${DIR}/icons/dice-2.png"
  "${DIR}/icons/dice-3.png"
  "${DIR}/icons/dice-4.png"
  "${DIR}/icons/dice-5.png"
  "${DIR}/icons/dice-6.png"
)

# Compute random die
DIE=$(( RANDOM % 6 ))

APP=/home/toz/Downloads/tmp/gdie2

# Panel
if [[ $(file -b "${ICON_ARRAY[DIE]}") =~ PNG|SVG ]]; then
  INFO="<img>${ICON_ARRAY[DIE]}</img>"
  INFO+="<click>$APP</click>"
else
  INFO+="<click>$APP</click>"
fi

# Tooltip
MORE_INFO="<tool>"
MORE_INFO+="$(( DIE + 1 ))"
MORE_INFO+="</tool>"

# Panel Print
echo -e "${INFO}"

# Tooltip Print
echo -e "${MORE_INFO}"

...I added the $APP variable.

Supporting script (gdie2):

#!/usr/bin/env bash
# Dependencies: bash>=3.2, coreutils, file

# Makes the script more portable
readonly DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Optional icon to display before the text
# Insert the absolute path of the icon
# Recommended size is 24x24 px
declare -r ICON_ARRAY=(
  "${DIR}/icons/dice-1.png"
  "${DIR}/icons/dice-2.png"
  "${DIR}/icons/dice-3.png"
  "${DIR}/icons/dice-4.png"
  "${DIR}/icons/dice-5.png"
  "${DIR}/icons/dice-6.png"
)

for i in {1..6}
do
	echo "<img>${DIR}/icons/dice-$i.png</img>"
	xfce4-panel --plugin-event=genmon-23:refresh:bool:true
done

exit 0

...this script cycles through the 6 dice making it look like they are spinning. Note: you need to change "genmon-23" to point to the name of your specific genmon instance (hover over the item in the Panel Properties Items tab.


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 2019-09-14 08:18:45

spnzdg
Member
From: Amsterdam
Registered: 2019-08-29
Posts: 23

Re: xfce4-panel-genmon: how to change random png to sequence ???

Very nice. That's what i needed. Thanks

cheers.

Offline

Registered users online in this topic: 0, guests: 1
[Bot] ClaudeBot

Board footer

Powered by FluxBB
Modified by Visman

[ Generated in 0.012 seconds, 7 queries executed - Memory usage: 530.13 KiB (Peak: 530.98 KiB) ]