YAD - Tips

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#761 Post by fredx181 »

Argolance wrote:Bonjour,
alarm script works fine!
Thanks.
Why not an optional icon in the system tray to launch the script and the same icon but very slightly flashing when the alarm is set and running in the background? :wink:

Cordialement.
Thanks for testing and suggestion !
I'm not sure if or when I'll continue improving this, there can be many options, like e.g. remember last settings, mute sound when the alarm goes off or set the volume etc.., a systray icon (with menu) indeed would be good.

Fred

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#762 Post by Argolance »

For example... :)
Attachments
mini-locale.gif
(5.54 KiB) Downloaded 262 times

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#763 Post by fredx181 »

Argolance wrote:For example... :)
Thanks, but how you get that (left side) animated icon in the system tray ?

Fred

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#764 Post by misko_2083 »

fredx181 wrote:
Argolance wrote:For example... :)
Thanks, but how you get that (left side) animated icon in the system tray ?

Fred

Code: Select all

#!/bin/bash
exec 3> >(yad --notification --listen)
while sleep 2; do
     echo "icon:gtk-ok" >&3
     sleep 2
     echo "icon:gtk-yes" >&3
     sleep 2
     echo "icon:gtk-no" >&3
done
exec 3>&-

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#765 Post by Argolance »

Bonjour,
misko_2083 is like Lucky Luck, he shoots faster than his shadow 8)
I don't remember which Forum member gave me these "while..." lines that work fine too:

Code: Select all

#!/bin/bash
command () {
echo -en "\\033[1;32m"
echo "VOUS-Y AVEZ CRÛ?"
} ; export -f command

while true; do echo 'icon:'/root/alarm_1.png; sleep 1; echo 'icon:/root/alarm_2.png'; sleep 1; echo 'icon:/root/alarm_3.png'; sleep 1; echo 'icon:/root/alarm_4.png'; sleep 1; done | yad --notification --icon-size=20 --auto-kill --no-middle --listen --text="Alarm is running in the background...
Click this icon and you will see the Eiffel Tower..." --command="urxvt -hold -e bash -c command" &
XPID=$!
sleep 60
kill $XPID

Regarding this script, how to make:

Code: Select all

yad --text-info="Doesn't work"
as --command option above work? Didn't found the solution, idem for this:

Code: Select all

yad --text-info < /root/my-documents/clipart/README-clipart.txt
Cheers
Attachments
alarm_icons.tar.gz
To unzip in /root...
(1.77 KiB) Downloaded 127 times

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#766 Post by fredx181 »

Argolance wrote:misko_2083 is like Lucky Luck, he shoots faster than his shadow Cool
:lol: Yes, watch MiskY, he's one of a kind !!
Thanks for the code and the icons, I was thinking for a while that it was a .gif image, but not not supported by yad --notification, this way works nicely too !
Regarding this script, how to make:
Code:
yad --text-info="Doesn't work"
Pipe the text to yad --text-info ?

Code: Select all

echo "Works" | yad --text-info
EDIT: also:

Code: Select all

yad --text-info --filename=/root/my-documents/clipart/README-clipart.txt
EDIT2: Regarding echo "Works" | yad --text-info

Code: Select all

 --command="bash -c 'echo "Works" | yad --text-info'"
should do

Fred

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#767 Post by Argolance »

Bonsoir,

Code: Select all

--command="yad --text-info --filename=/root/my-documents/clipart/README-clipart.txt"

Code: Select all

--command="bash -c 'echo "Works" | yad --text-info'"
Both do the job. Thanks!

Cordialement.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#768 Post by vovchik »

Dear all,

What about this for self-contained animation?

Code: Select all

#!/bin/bash

A_ICON="/tmp/alarm1a.svg"
B_ICON="/tmp/alarm1b.svg"
C_ICON="/tmp/alarm1c.svg"
TOOLTIP="Alarm is running in the background...
Click this icon and you will see a text box..." 
MSG="It works!!!"
COL="red"
if [ ! -e "$A_ICON" ]; then
	SVG="<""svg width='22' height='22' viewBox='0 0 100 100'>
		<mask id='mask_circle'>
		  <circle cx='50' cy='50' r='50' fill='white'/>
		  <circle cx='50' cy='50' r='12' fill='gray'/>
		</mask>
		<linearGradient x1='20' y1='60' x2='60' y2='40' id='lg' 
		 gradientUnits='userSpaceOnUse'>
		  <stop style='stop-color:dark$COL;stop-opacity:1' offset='0'/>
		  <stop style='stop-color:$COL;stop-opacity:1' offset='1'/>
		</linearGradient>
	  <circle cx='50' cy='50' r='28%' style='fill:dark$COL'/>
	  <circle cx='50' cy='50' r='23%' style='fill:url(#lg);
	   stroke:gray;stroke-width:3'/>
	</svg>"
   echo "$SVG" > $A_ICON
   SVG=$(echo "$SVG" | sed 's/28%/38%/g' | sed 's/23%/33%/g')
   echo "$SVG" > $B_ICON
   SVG=$(echo "$SVG" | sed 's/38%/48%/g' | sed 's/33%/43%/g')
   echo "$SVG" > $C_ICON
fi
while true; do 
	echo 'icon:'$A_ICON; 
	sleep 0.25; 
	echo 'icon:'$B_ICON; 
	sleep 0.25; 
	echo 'icon:'$C_ICON; 
	sleep 0.25; 
	echo 'icon:'$B_ICON; 
	sleep 0.25; 
done | yad \
--notification \
--icon-size=20 \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="$TOOLTIP" \
--command="bash -c 'echo $MSG | yad --title=\"Alarm box\" \
--window-icon=\"$C_ICON\" \
--text-info'" &
XPID=$!
# select timeout in seconds
sleep 20
kill $XPID
With kind regards,
vovchik

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#769 Post by misko_2083 »

Argolance wrote:Bonjour,
misko_2083 is like Lucky Luck, he shoots faster than his shadow 8)
Watch out Dalton brothers. ;)

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#770 Post by Argolance »

Bonsoir,
vovchik wrote:What about this for self-contained animation?
Wow, very skilful/impressive! :o

Cordialement.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#771 Post by fredx181 »

vovchik wrote:What about this for self-contained animation?
Thanks very much vovchik ! Great stuff ! (as always :D )

Fred

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#772 Post by fredx181 »

Hi all, here's new alarm script (2 slightly different), changes:
- Using preferences file ~/.yalrm
(remembering now most previously used settings for next time run)
- Supports now setting the alarm for next day, same hour (previously didn't work) (but gives prompt 'Are you sure' yes/no in case accidentally set)
- Display of tray icon as long as waiting for the alarm to go off (thanks Argolance and vovchik :) )
TODO maybe: Multiple alarms can be set, but, as it is now, everytime a new tray icon appears, better only one icon but tooltip and message when left click changed when setting new alarm

First script: depends on the 4 icons Argolance attached here: http://murga-linux.com/puppy/viewtopic. ... 89#1042989
Extract and make sure they are in /root, e.g. '/root/alarm_1.png', '/root/alarm_2.png' etc..

Code: Select all

#!/bin/bash

alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

sound="$2"
if [ ! -f "$sound" ]; then
yad --center --title="No sound file" --text="  No sound file selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=/root/alarm_4.png --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

show_icon () {
while true; do echo 'icon:'/root/alarm_1.png; sleep 1; echo 'icon:/root/alarm_2.png'; sleep 1; echo 'icon:/root/alarm_3.png'; sleep 1; echo 'icon:/root/alarm_4.png'; sleep 1; done | yad --notification --auto-kill --no-middle --listen --text="Alarm is running in the background...
Set to $hr:$mn" --command="bash -c command" &
export XPID=$!
}; export -f show_icon

hrnow=$(echo $(date +"%k"))

# For when trying to set alarm for next day e.g. from current 21:00 to target 6:00
if [ "$hr" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon 
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
echo "Wake Up!"

while [ $repeat -gt 0 ]; do
$PLAYER "$sound" </dev/null >/dev/null 2>&1 &
sleep $dur
pidplayer="$(pgrep -lf "$PLAYER $sound" | awk '{ print $1 }')"
[ -n "$pidplayer" ] && kill -9 $pidplayer
repeat=$(($repeat-1))
if [ $repeat -gt 0 ]; then
  if [ $dur -lt $interval ]; then
  sleep $(($interval-$dur)) 2> /dev/null
#  else
#  sleep $interval 2> /dev/null
  fi
fi
done

}; export -f alrm

# set hour and minute at current time in yad GUI
hour=$(echo -e "$(seq -w $(date +"%H") 23)\n$(seq -w 00 $(date +"%H"))" | sed '$ d' |xargs | tr ' ' ':')
min=$(echo -e "$(seq -w $(date +"%M") 59)\n$(seq -w 00 $(date +"%M"))" | sed '$ d' |xargs|tr ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

while :
do 
  date +"%H":"%M":"%S"
  sleep 0.5
done | yad --plug="$$" --tabnum=1 --form --cycle-read --columns=2 --field="\t\t<i><b>S e t  A l a r m</b></i>\t:lbl" --field="Current Time:: " &

yad --plug="$$" --tabnum=2 --center --title="Alarm" --form --columns=4 --item-separator=":" \
--field="Player::sfl" "$PLAYER" \
--field="Sound::sfl" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur:01..10000:01" \
--field="Set Alarm:fbtn" 'bash -c "alrm %1 %2 %3 %4 %5 %6 %7 %8 %9"' \
--no-buttons &
yad --center --title="Alarm" --paned --key="$$" --orient=vert --no-buttons
Second script contains the icon setup for yad --notification that vovchik provided (self containing), for the rest it's the same as above.

Code: Select all

#!/bin/bash

export A_ICON="/tmp/alarm1a.svg"
export B_ICON="/tmp/alarm1b.svg"
export C_ICON="/tmp/alarm1c.svg"
COL="red"
if [ ! -e "$A_ICON" ]; then
   SVG="<""svg width='22' height='22' viewBox='0 0 100 100'>
      <mask id='mask_circle'>
        <circle cx='50' cy='50' r='50' fill='white'/>
        <circle cx='50' cy='50' r='12' fill='gray'/>
      </mask>
      <linearGradient x1='20' y1='60' x2='60' y2='40' id='lg'
       gradientUnits='userSpaceOnUse'>
        <stop style='stop-color:dark$COL;stop-opacity:1' offset='0'/>
        <stop style='stop-color:$COL;stop-opacity:1' offset='1'/>
      </linearGradient>
     <circle cx='50' cy='50' r='28%' style='fill:dark$COL'/>
     <circle cx='50' cy='50' r='23%' style='fill:url(#lg);
      stroke:gray;stroke-width:3'/>
   </svg>"
   echo "$SVG" > $A_ICON
   SVG=$(echo "$SVG" | sed 's/28%/38%/g' | sed 's/23%/33%/g')
   echo "$SVG" > $B_ICON
   SVG=$(echo "$SVG" | sed 's/38%/48%/g' | sed 's/33%/43%/g')
   echo "$SVG" > $C_ICON
fi

alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

sound="$2"
if [ ! -f "$sound" ]; then
yad --center --title="No sound file" --text="  No sound file selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=$C_ICON --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

show_icon () {
while true; do
   echo 'icon:'$A_ICON;
   sleep 0.25;
   echo 'icon:'$B_ICON;
   sleep 0.25;
   echo 'icon:'$C_ICON;
   sleep 0.25;
   echo 'icon:'$B_ICON;
   sleep 0.25;
done | yad \
--notification \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="Alarm is running in the background...
Set to $hr:$mn" \
--command="bash -c command" &
XPID=$!
}; export -f show_icon

hrnow=$(echo $(date +"%k"))

# For when trying to set alarm for next day e.g. from current 21:00 to target 6:00
if [ "$hr" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon 
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
echo "Wake Up!"

while [ $repeat -gt 0 ]; do
$PLAYER "$sound" </dev/null >/dev/null 2>&1 &
sleep $dur
pidplayer="$(pgrep -lf "$PLAYER $sound" | awk '{ print $1 }')"
[ -n "$pidplayer" ] && kill -9 $pidplayer
repeat=$(($repeat-1))
if [ $repeat -gt 0 ]; then
  if [ $dur -lt $interval ]; then
  sleep $(($interval-$dur)) 2> /dev/null
#  else
#  sleep $interval 2> /dev/null
  fi
fi
done

}; export -f alrm

# set hour and minute at current time in yad GUI
hour=$(echo -e "$(seq -w $(date +"%H") 23)\n$(seq -w 00 $(date +"%H"))" | sed '$ d' |xargs | tr ' ' ':')
min=$(echo -e "$(seq -w $(date +"%M") 59)\n$(seq -w 00 $(date +"%M"))" | sed '$ d' |xargs|tr ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

while :
do 
  date +"%H":"%M":"%S"
  sleep 0.5
done | yad --plug="$$" --tabnum=1 --form --cycle-read --columns=2 --field="\t\t<i><b>S e t  A l a r m</b></i>\t:lbl" --field="Current Time:: " &

yad --plug="$$" --tabnum=2 --center --title="Alarm" --form --columns=4 --item-separator=":" \
--field="Player::sfl" "$PLAYER" \
--field="Sound::sfl" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur:01..10000:01" \
--field="Set Alarm:fbtn" 'bash -c "alrm %1 %2 %3 %4 %5 %6 %7 %8 %9"' \
--no-buttons &
yad --center --title="Alarm" --paned --key="$$" --orient=vert --no-buttons
Fred

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#773 Post by vovchik »

Dear Fred,

Great work. Works nicely on my setup, and it is useful. Very nice coding., too :) The only thing missing, and pretty easy to add, is tooltips for the widgets (e.g. duration, interval).

Thanks for this little gem.

With kind regards,
vovchik

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#774 Post by fredx181 »

Thanks vovchik !
The only thing missing, and pretty easy to add, is tooltips for the widgets (e.g. duration, interval).
I have no idea how, isn't that only supported for buttons ?

Fred

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#775 Post by vovchik »

Dear Fred,

You are right. I don't really know how (yet). In c and gtkdialog you can do that by setting a widget's properties. With yad, it's a different story. Maybe there is a way. Time to look at the manual and other people's code, I guess. :)

With kind regards,
vovchik

User avatar
misko_2083
Posts: 114
Joined: Tue 08 Nov 2016, 13:42

#776 Post by misko_2083 »

Fredx, If you move the current time to the window title bar, can you think of anything that you would use the first tab for?

Code: Select all

#!/bin/bash

win_class="timer_class"
TITLE="Alarm - Current Time"

export A_ICON="/tmp/alarm1a.svg"
export B_ICON="/tmp/alarm1b.svg"
export C_ICON="/tmp/alarm1c.svg"
COL="red"
if [ ! -e "$A_ICON" ]; then
   SVG="<""svg width='22' height='22' viewBox='0 0 100 100'>
      <mask id='mask_circle'>
        <circle cx='50' cy='50' r='50' fill='white'/>
        <circle cx='50' cy='50' r='12' fill='gray'/>
      </mask>
      <linearGradient x1='20' y1='60' x2='60' y2='40' id='lg'
       gradientUnits='userSpaceOnUse'>
        <stop style='stop-color:dark$COL;stop-opacity:1' offset='0'/>
        <stop style='stop-color:$COL;stop-opacity:1' offset='1'/>
      </linearGradient>
     <circle cx='50' cy='50' r='28%' style='fill:dark$COL'/>
     <circle cx='50' cy='50' r='23%' style='fill:url(#lg);
      stroke:gray;stroke-width:3'/>
   </svg>"
   echo "$SVG" > $A_ICON
   SVG=$(echo "$SVG" | sed 's/28%/38%/g' | sed 's/23%/33%/g')
   echo "$SVG" > $B_ICON
   SVG=$(echo "$SVG" | sed 's/38%/48%/g' | sed 's/33%/43%/g')
   echo "$SVG" > $C_ICON
fi

function change_title {
local yad_xid

# need some time to register window class with X
while [[ ${yad_xid} == "" ]]; do
   # get Xwindow id
   yad_xid="$(wmctrl -lx | grep -e "yad.${win_class}" |  grep -oE "[0-9a-z]{10}")"
done

# convert to decimal number
yad_xid="$(echo $((${yad_xid})))"

while true
 do
   wmctrl -i -r "${yad_xid}" -N "$TITLE : $(date '+%T')" 2>/dev/null || break
   sleep 1
done
}


alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

sound="$2"
if [ ! -f "$sound" ]; then
yad --center --title="No sound file" --text="  No sound file selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=$C_ICON --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

show_icon () {
while true; do
   echo 'icon:'$A_ICON;
   sleep 0.25;
   echo 'icon:'$B_ICON;
   sleep 0.25;
   echo 'icon:'$C_ICON;
   sleep 0.25;
   echo 'icon:'$B_ICON;
   sleep 0.25;
done | yad \
--notification \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="Alarm is running in the background...
Set to $hr:$mn" \
--command="bash -c command" &
XPID=$!
}; export -f show_icon

hrnow=$(echo $(date +"%k"))

# For when trying to set alarm for next day e.g. from current 21:00 to target 6:00
if [ "$hr" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
echo "Wake Up!"

while [ $repeat -gt 0 ]; do
$PLAYER "$sound" </dev/null >/dev/null 2>&1 &
sleep $dur
pidplayer="$(pgrep -lf "$PLAYER $sound" | awk '{ print $1 }')"
[ -n "$pidplayer" ] && kill -9 $pidplayer
repeat=$(($repeat-1))
if [ $repeat -gt 0 ]; then
  if [ $dur -lt $interval ]; then
  sleep $(($interval-$dur)) 2> /dev/null
#  else
#  sleep $interval 2> /dev/null
  fi
fi
done

}; export -f alrm

# set hour and minute at current time in yad GUI
hour=$(echo -e "$(seq -w $(date +"%H") 23)\n$(seq -w 00 $(date +"%H"))" | sed '$ d' |xargs | tr ' ' ':')
min=$(echo -e "$(seq -w $(date +"%M") 59)\n$(seq -w 00 $(date +"%M"))" | sed '$ d' |xargs|tr ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

# Keep changing the title to current time
change_title &

while :
do
  echo "What to do with this tab?"
  sleep 0.5
done | yad --plug="$$" --tabnum=1 --form --cycle-read --columns=2 --field="\t\t<i><b>S e t  A l a r m</b></i>\t:lbl" --field="Current Time:: " &

yad --plug="$$" --tabnum=2 --center --title="Alarm" --form --columns=4 --item-separator=":" \
--field="Player::sfl" "$PLAYER" \
--field="Sound::sfl" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur:01..10000:01" \
--field="Set Alarm:fbtn" 'bash -c "alrm %1 %2 %3 %4 %5 %6 %7 %8 %9"' \
--no-buttons &
yad --class="${win_class}" --center --title="$TITLE : $(date '+%T')" --paned --key="$$" --orient=vert --no-buttons

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#777 Post by Argolance »

Hello,
I had fun internationalizing the first version.... Maybe a little too soon? The same thing can be done for the second one!
I think a right click menu to let user stop a running alarm process would be useful...

EDIT 1: I added a configuration directory /root/.yarlm automatically built at startup and a configuration file inside called "prefs". May be a conflict between the "old" configuration file with the directory (same name).
I forgot the desktop file. :?
EDIT 2: The file "/usr/share/audio/2barks.wav" may be the defautl sound file?
aplay as player?
a button to quit the gui?

Cordialement.
Attachments
191130_143943_629x168_easyshot.jpg
(14.88 KiB) Downloaded 251 times
set_alarm-191130.pet
(5.22 KiB) Downloaded 132 times
Last edited by Argolance on Sat 30 Nov 2019, 15:44, edited 3 times in total.

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#778 Post by vovchik »

Dear misko_2083 and fred and argolance,

I like the idea of the current time in the window bar. As for the empty area, what about a checkbox (relative time) and spinbox for relative time-setting (i.e. in fifteen mintues)?

With kind regards,
vovchik

User avatar
Argolance
Posts: 3767
Joined: Sun 06 Jan 2008, 22:57
Location: PORT-BRILLET (Mayenne - France)
Contact:

#779 Post by Argolance »

vovchik wrote:I like the idea of the current time in the window bar.
Me too, but not static time: so I am not sure it is possible!
As for the empty area, what about a checkbox (relative time) and spinbox for relative time-setting (i.e. in fifteen mintues)?
Sorry, I do not understand what you mean... :oops:

Cordialement.

User avatar
fredx181
Posts: 4448
Joined: Wed 11 Dec 2013, 12:37
Location: holland

#780 Post by fredx181 »

Here's again new alarm script with some basic changes (a fix and new addition).
(didn't add any of the above suggestions (yet), will reply about it later)
- Fixed that still the process ID of the script was left after closing the GUI
- Added (right-click) menu to tray icon, with choice of:
-- "Cancel Alarm and Exit tray"
-- "Exit tray only"
Which are important choices IMO as a user should be able to cancel the alarm or to exit the tray icon (without canceling the alarm, btw) (the icon is consuming some CPU)

This is the version with the yad --notification setup by vovchik , which I prefer because it's self containing:

Code: Select all

#!/bin/bash

export A_ICON="/tmp/alarm1a.svg"
export B_ICON="/tmp/alarm1b.svg"
export C_ICON="/tmp/alarm1c.svg"
COL="red"
if [ ! -e "$A_ICON" ]; then
   SVG="<""svg width='22' height='22' viewBox='0 0 100 100'>
      <mask id='mask_circle'>
        <circle cx='50' cy='50' r='50' fill='white'/>
        <circle cx='50' cy='50' r='12' fill='gray'/>
      </mask>
      <linearGradient x1='20' y1='60' x2='60' y2='40' id='lg'
       gradientUnits='userSpaceOnUse'>
        <stop style='stop-color:dark$COL;stop-opacity:1' offset='0'/>
        <stop style='stop-color:$COL;stop-opacity:1' offset='1'/>
      </linearGradient>
     <circle cx='50' cy='50' r='28%' style='fill:dark$COL'/>
     <circle cx='50' cy='50' r='23%' style='fill:url(#lg);
      stroke:gray;stroke-width:3'/>
   </svg>"
   echo "$SVG" > $A_ICON
   SVG=$(echo "$SVG" | sed 's/28%/38%/g' | sed 's/23%/33%/g')
   echo "$SVG" > $B_ICON
   SVG=$(echo "$SVG" | sed 's/38%/48%/g' | sed 's/33%/43%/g')
   echo "$SVG" > $C_ICON
fi

alrm () {
PLAYER="$1"
if [ -z "$PLAYER" ]; then
yad --center --title="No player" --text="  No player selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^PLAYER=.*#PLAYER="'"$PLAYER"'"#' $HOME/.yalrm

sound="$2"
if [ ! -f "$sound" ]; then
yad --center --title="No sound file" --text="  No sound file selected   " --width=350 --button="gtk-close:0"
exit
fi
sed -i 's#^sound=.*#sound="'"$sound"'"#' $HOME/.yalrm

export hr="$3"
[ "${hr:0:1}" = '0' ] && hr=${hr#?}
export mn="$5"
target="$hr:$mn"
repeat="$4"
sed -i 's#^repeat=.*#repeat="'"$repeat"'"#' $HOME/.yalrm
interval="$6"
sed -i 's#^interval=.*#interval="'"$interval"'"#' $HOME/.yalrm
dur="$7"
sed -i 's#^dur=.*#dur="'"$dur"'"#' $HOME/.yalrm

command () {
yad --undecorated --image=$C_ICON --borders 12 --title="Alarm" --text="    \t<b>Alarm set to $hr:$mn</b> " --geometry=280x50-40-50 --no-buttons --timeout 4
} ; export -f command

cancel_quit_tray () {
kill $(cat /tmp/yalrm_apid 2> /dev/null)
kill $(cat /tmp/yalrm_xpid 2> /dev/null)
}; export -f cancel_quit_tray

quit_tray () {
kill $(cat /tmp/yalrm_xpid 2> /dev/null)
}; export -f quit_tray

show_icon () {
(
echo menu:"Cancel Alarm and Exit tray!bash -c cancel_quit_tray!gtk-quit|Exit tray only!bash -c quit_tray!gtk-quit"
while true; do
   echo 'icon:'$A_ICON;
   sleep 0.25;
   echo 'icon:'$B_ICON;
   sleep 0.25;
   echo 'icon:'$C_ICON;
   sleep 0.25;
   echo 'icon:'$B_ICON;
   sleep 0.25;
done
) | yad \
--notification \
--image="$C_ICON" \
--auto-kill \
--no-middle \
--listen \
--text="Alarm is running in the background...
Set to $hr:$mn" \
--command="bash -c command" &
export XPID=$!
echo $XPID > /tmp/yalrm_xpid
}; export -f show_icon

hrnow=$(echo $(date +"%k"))

(
# For when trying to set alarm for next day e.g. from current 21:00 to target 6:00
if [ "$hr" -eq "$hrnow" ] &&  [ "$mn" -le "$(date +"%M")" ]; then
# prompt yes/no in case accidentally chosen current hour but less than current minute
yad --center --title="Are you sure?" --text="  Are you sure to set the alarm to $target (next day) ?" --width=400 --button="Yes:0"  --button="No:1"
[ $? -ne 0 ] && exit
command; show_icon 
sleep $(( $(date --date="$(((23+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) + 3600 ))
elif [ "$hr" -lt "$hrnow" ]; then
command; show_icon
sleep $(( $(date --date="$(((24+$hr) - $hrnow)):$mn" +%s) - $(date --date="00:$(date +"%M"):$(date +"%S")" +%s) ))
else
command; show_icon
sleep $(( $(date --date="$target" +%s) - $(date +%s) ));
fi

kill $XPID
echo "Wake Up!"

while [ $repeat -gt 0 ]; do
$PLAYER "$sound" </dev/null >/dev/null 2>&1 &
sleep $dur
pidplayer="$(pgrep -lf "$PLAYER $sound" | awk '{ print $1 }')"
[ -n "$pidplayer" ] && kill -9 $pidplayer
repeat=$(($repeat-1))
if [ $repeat -gt 0 ]; then
  if [ $dur -lt $interval ]; then
  sleep $(($interval-$dur)) 2> /dev/null
#  else
#  sleep $interval 2> /dev/null
  fi
fi
done
) &
export ALPID=$!
echo $ALPID > /tmp/yalrm_apid
wait $ALPID
}; export -f alrm

# set hour and minute at current time in yad GUI
hour=$(echo -e "$(seq -w $(date +"%H") 23)\n$(seq -w 00 $(date +"%H"))" | sed '$ d' |xargs | tr ' ' ':')
min=$(echo -e "$(seq -w $(date +"%M") 59)\n$(seq -w 00 $(date +"%M"))" | sed '$ d' |xargs|tr ' ' ':')

# create preference file $HOME/.yalrm, if not exists
if [ ! -f $HOME/.yalrm ]; then
echo "PLAYER=mplayer
sound=""
repeat=01
interval=00
dur=05
" > $HOME/.yalrm
fi

. $HOME/.yalrm

while :
do 
  date +"%H":"%M":"%S"
pidyad="$(pgrep -lf "yad --plug=$$" | awk '{ print $1 }')"
[ -z "$pidyad" ] && break
  sleep 0.5
done | yad --plug="$$" --tabnum=1 --form --cycle-read --columns=2 --field="\t\t<i><b>S e t  A l a r m</b></i>\t:lbl" --field="Current Time:: " &

yad --plug="$$" --tabnum=2 --center --title="Alarm" --form --columns=4 --item-separator=":" \
--field="Player::sfl" "$PLAYER" \
--field="Sound::sfl" "$sound" \
--field="Hour::CB" "$hour" \
--field="Repeat::NUM" "$repeat:01..300:01" \
--field="Minutes::CB" "$min" \
--field="Interval:\n(seconds):NUM" "$interval:00..1000:01" \
--field="Duration:\n(seconds):NUM" "$dur:01..10000:01" \
--field="Set Alarm:fbtn" 'bash -c "alrm %1 %2 %3 %4 %5 %6 %7 %8 %9"' \
--no-buttons &
yad --center --title="Alarm" --paned --key="$$" --orient=vert --no-buttons
Fred

Post Reply