You are not logged in.

#1 2019-11-15 23:36:32

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Alarm clock scripts

The devs have been having some discussion about providing an alarm/alert script, and this is one that I have found in the YAD Wiki. I've tweaked some of the paths (icon, sound file, use mpv etc) and added the current time to the layout - it looks promising.

CONS: Even though it adds a notification to the systray, I can't see a way of cancelling the alarm as it stands. Perhaps the PID can be captured and used to kill the process?

yad-alarm2.jpg

#!/bin/bash
#
# Alarm clock for PCLinuxOS
#
# Don't miss important times and events. Turn your computer 
# into the perfect wake up system. Set the alarm and get the 
# Pizza out of the oven in perfect time.
#
# Author: D.M-Wilhelm (Leiche)
# Email: meisssw01 at gmail.com
# Licence: GPL
# First build: May Wed 11 2011
# Last build: Jul Sun 10 2011
# fixed icon display in systray, move zenity,
# based now on yad.
#
Encoding=UTF-8
#
# i18n - Internationalization - Internationalisierung
#
export TEXTDOMAIN=alert_clock
export TEXTDOMAINDIR="/usr/share/locale"
#
# define some variables - Definierung einiger Variablen 
#
TITLE="Alarm Clock"
ICON="/usr/share/icons/Paper/48x48/apps/alarm-clock.png"

#
#question - Frage
#
function menu {
COUNTDOWN=$(yad --entry --text "Time now is $(date +"%H:%m")" --entry-label "Enter minutes until alarm..." --numeric --title="$TITLE" --window-icon=$ICON \
            --image=$ICON \
            --button=$"Change alarm sound:2" \
            --button=$"Test:3" \
            --button="gtk-ok:0" \
            --button="gtk-close:1" \
           )
ret=$?

[[ $ret -eq 1 ]] && exit 0
#
#change sound - Sound ändern
#
if [[ $ret -eq 2 ]]; then
    CHANGE=$(yad --title="$TITLE" --window-icon=$ICON \
        --file --width=600 --height=500 \
        --text=$"<b>Choose your own audio file as alert!</b>
________________________________________________")
        if [ -z "$CHANGE" ];then 
        exec alert_clock
        exit 0
        else
        mkdir $HOME/.config/alert-clock
        rm -rf $HOME/.config/alert-clock/alert sleep 1
        ln -s "$CHANGE" $HOME/.config/alert-clock/alert
        yad --title $"$TITLE" \
            --button="gtk-ok:0" \
            --width 300 \
            --window-icon=$ICON \
            --text=$"Your own sound is set!!"
        fi
menu        
fi
#
#Test sound - Klang testen
#
if [[ $ret -eq 3 ]]; then
    if [ -f $HOME/.config/alert-clock/alert ]; then
    SOUND="$HOME/.config/alert-clock/alert"
    else
    SOUND='/usr/share/alert_clock/alarm.ogg'
    fi
mpv "$SOUND" | yad --title $"$TITLE" \
                 --button="gtk-ok:0" \
                 --width 300 \
                 --window-icon=$ICON \
                 --text=$"Exit sound test!!"
killall mpv
menu                 
fi
}
menu
#
#progress - Prozess
#
if [ "$COUNTDOWN" = "" ];then
exit
else
echo you enter "$COUNTDOWN" minutes
TIMER=$(echo $(($COUNTDOWN*60)))
TASK1=$(date -s "+$TIMER seconds" 2>/dev/null | cut -d " " -f4)
exec 3> >(yad --notification --command=CMD --image=$ICON --listen)
echo tooltip: $"Alarm clock was set to $COUNTDOWN minutes and notifiers at $TASK1!" >&3
sleep $TIMER
exec 3>&-
#
#check wich sound - auf Audio prüfen
#
if [ -f $HOME/.config/alert-clock/alert ]; then
    SOUND="$HOME/.config/alert-clock/alert"
    else
    SOUND='/usr/share/alert_clock/alarm.ogg'
fi
#
#alert output - Alarm Ausgabe
#
(mpv "$SOUND") | yad --title $"$TITLE" \
                 --button="gtk-ok:0" \
                 --width 300 --image=$ICON \
                 --window-icon=$ICON \
                 --text=$"<b>Time is over!!</b>"
                 exit;
fi
exit

If anyone would like to polish this, or suggest alternatives, then please do so! smile


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#2 2019-11-16 00:09:06

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

I do like the gui.

I did notice that there seems to be no way to cancel the sound test without ctrl+c in term, guessing that 'killall mpv' never gets executed.

Anything against using 'at' as back thingy? (It does survive the reboot) and once the timer is set the gui can be closed and forgotten. Also one can set many timers using variety of time formats.

I guess there is no easy way to stop sounds unless premaking player enviroment (pids?, pipe controled mpv?).

Last edited by brontosaurusrex (2019-11-16 00:31:44)

Offline

#3 2019-11-16 00:31:27

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

No objection to at, except it isn't installed in a default BL. It is only 157kb though, but make sure to use --no-install-recommends or a vast amount of libs and mail bloat comes in with it.

Why not post the at script you found here?


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#4 2019-11-16 00:33:48

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

beepmein

A cli experiment at how could a simple reminder/alarm thing work (using linux 'at' command).

Usage example:

beepmein 15            # minutes
beepmein --alarm 7:30  # hh:mm
beepmein --help        # for more

And will ask for reason, which you can provide or skip by pressing return.

edit, test playback and notifications, kill playback

beepmein --reaction "woot"
beepmein --reaction --alarm "alarm" & sleep 12 && killall beepmein
killall beepmein # to stop playback

Cons:  'at' doesn't use seconds, it will round to full minute, so your 'beepmein 1' may happen sooner than you think.

Last edited by brontosaurusrex (2019-11-17 09:04:58)

Offline

#5 2019-11-16 02:13:21

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

In the yad script, the tray icon can be dismissed by middle-clicking, but the child process for the timer keeps on going sad

I don't know enough about exec redirects to kill the zombie! monkey


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#6 2019-11-16 03:52:45

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

damo wrote:

In the yad script, the tray icon can be dismissed by middle-clicking, but the child process for the timer keeps on going sad

Either disable the middle click (in yad 0.42)

yad --help-notification
Usage:
  yad [OPTION...] - Yet another dialoging program

Notification icon options
  --notification                                 Display notification
  --menu=STRING                                  Set initial popup menu
  --no-middle                                    Disable exit on middle click
  --hidden                                       Doesn't show icon at startup
  --icon-size=SIZE                               Set icon size for fully specified icons (default - 16)

or use the timeout, and since entry is deprecated in the gtk3 versions switch to form dialog

#!/bin/bash
#
# Alarm clock for PCLinuxOS
#
# Don't miss important times and events. Turn your computer 
# into the perfect wake up system. Set the alarm and get the 
# Pizza out of the oven in perfect time.
#
# Author: D.M-Wilhelm (Leiche)
# Email: meisssw01 at gmail.com
# Licence: GPL
# First build: May Wed 11 2011
# Last build: Jul Sun 10 2011
# fixed icon display in systray, move zenity,
# based now on yad.
#
Encoding=UTF-8
#
# i18n - Internationalization - Internationalisierung
#
export TEXTDOMAIN=alert_clock
export TEXTDOMAINDIR="/usr/share/locale"
#
# define some variables - Definierung einiger Variablen 
#
TITLE="Alarm Clock"
ICON="/usr/share/icons/Paper/48x48/apps/alarm-clock.png"

#
#question - Frage
#
function menu {
COUNTDOWN=$(yad --form --text "Time now is $(date +"%H:%m")" --field "Enter minutes until alarm...":NUM  1 --title="$TITLE" --window-icon=$ICON \
            --image=$ICON \
            --button=$"Change alarm sound:2" \
            --button=$"Test:3" \
            --button="gtk-ok:0" \
            --button="gtk-close:1" \
           )
ret=$?

[[ $ret -eq 1 ]] && exit 0
#
#change sound - Sound ändern
#
if [[ $ret -eq 2 ]]; then
    CHANGE=$(yad --title="$TITLE" --window-icon=$ICON \
        --file --width=600 --height=500 \
        --text=$"\n\t<b>Choose your own audio file as alert!</b>\n")
        if [ -z "$CHANGE" ];then 
        exec alert_clock
        exit 0
        else
        mkdir $HOME/.config/alert-clock
        rm -rf $HOME/.config/alert-clock/alert sleep 1
        ln -s "$CHANGE" $HOME/.config/alert-clock/alert
        yad --title $"$TITLE" \
            --button="gtk-ok:0" \
            --width 300 \
            --window-icon=$ICON \
            --text=$"Your own sound is set!!"
        fi
menu        
fi
#
#Test sound - Klang testen
#
if [[ $ret -eq 3 ]]; then
    if [ -f $HOME/.config/alert-clock/alert ]; then
    SOUND="$HOME/.config/alert-clock/alert"
    else
    SOUND='/usr/share/alert_clock/alarm.ogg'
    fi
mpv "$SOUND" | yad --title $"$TITLE" \
                 --button="gtk-ok:0" \
                 --width 300 \
                 --window-icon=$ICON \
                 --text=$"Exit sound test!!"
killall mpv
menu                 
fi
}
menu
#
#progress - Prozess
#
if [ "$COUNTDOWN" = "" ];then
exit
else

echo you enter "${COUNTDOWN%"|"*}" minutes
TIMER=$(echo $((${COUNTDOWN%"|"*}*60)))
TASK1=$(date -s "+$TIMER seconds" 2>/dev/null | cut -d " " -f4)
temp=$(mktemp -u --tmpdir alarm.XXXXXXXX)
mkfifo $temp

exec 3<> $temp
timeout --preserve-status $TIMER yad --notification --command=CMD --image=$ICON --listen <&3 & _pid=$!
echo "tooltip:Alarm clock was set to ${COUNTDOWN%"|"*} minutes \nand notifiers at $TASK1!" >&3
wait $_pid
rm $temp
exec 3>&-
#
#check wich sound - auf Audio prüfen
#
if [ -f $HOME/.config/alert-clock/alert ]; then
    SOUND="$HOME/.config/alert-clock/alert"
    else
    SOUND='/usr/share/alert_clock/alarm.ogg'
fi
#
#alert output - Alarm Ausgabe
#
(mpv "$SOUND") | yad --title $"$TITLE" \
                 --button="gtk-ok:0" \
                 --width 300 --image=$ICON \
                 --window-icon=$ICON \
                 --text=$"<b>Time is over!!</b>"
                 exit;
fi
exit

Edit; forgot about fifo

Last edited by misko_2083 (2019-11-16 04:56:05)

Offline

#7 2019-11-16 04:18:32

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

@misko_2083

Clever stuff! Couple of issues though:

The tooltips text isn't displaying (I had the same problem when experimenting with pipes);

Killing the yad systray notification causes the alarm to sound immediately. The script should exit before mpv "$SOUND" runs.


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#8 2019-11-16 04:36:34

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

damo wrote:

@misko_2083

Clever stuff! Couple of issues though:

The tooltips text isn't displaying (I had the same problem when experimenting with pipes);

Killing the yad systray notification causes the alarm to sound immediately. The script should exit before mpv "$SOUND" runs.

Tooltip is my fault, needed a fifo pipe. Fixed in edit.
If it still doesn't work maybe some sleep is needed before setting the tooltip.

Second issue, wait returns exit status, insert check after wait

wait $_pid
[ $? -eq 252 ] && exit

Last edited by misko_2083 (2019-11-16 04:38:00)

Offline

#9 2019-11-16 04:46:23

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

You could also use timeout

timeout -s HUP  0.1 speaker-test -t sine -f 1000  > /dev/null 2>&1
sleep 0.1

or with sigkill

timeout -s KILL  0.1 speaker-test -t sine -f 1000  > /dev/null 2>&1
sleep 0.1

instead of

        ( speaker-test -t sine -f 1000 ) > /dev/null 2>&1 & pid=$! 
        sleep 0.1s
        { kill -9 $pid;wait $pid; } > /dev/null 2>&1
        sleep 0.1s

Offline

#10 2019-11-16 08:21:08

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

I've added the tweaks, and the script shuts down gracefully smile

Since a middle mouse button isn't universal, and needs to be set up for a trackpad, I've found a way to use the left button to achieve the same thing (which is probably more natural anyway).

This is the relevant section:

# add handler for tray icon left click
function on_click() {
    xdotool click 2
}
export -f on_click

if [ "$COUNTDOWN" = "" ];then
    exit
else

echo You entered "${COUNTDOWN%"|"*}" minutes
TIMER=$(echo $((${COUNTDOWN%"|"*}*60)))
TASK1=$(date -s "+$TIMER seconds" 2>/dev/null | cut -d " " -f4)
temp=$(mktemp -u --tmpdir alarm.XXXXXXXX)

mkfifo $temp

exec 3<> $temp
timeout --preserve-status $TIMER yad --notification --command="bash -c on_click" --image=$ICON --listen <&3 & _pid=$!
echo "tooltip:Alarm clock is set to sound at $TASK1\n\nLeft click to cancel alarm" >&3

wait $_pid
[ $? -eq 252 ] && rm -f $temp && exit
rm $temp
exec 3>&-
#

Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#11 2019-11-16 08:44:14

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

misko_2083: Nice, will fix it.

Last edited by brontosaurusrex (2019-11-16 12:50:47)

Offline

#12 2019-11-16 10:33:09

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

damo wrote:

I've added the tweaks, and the script shuts down gracefully smile
I've found a way to use the left button to achieve the same thing (which is probably more natural anyway).

cool

There is a special command "quit".

quit   Exit the program. Middle click on icon also send quit command.

Return status is 0 when it's called, even with the right click menu.

timeout --preserve-status $TIMER yad --notification  --listen <&3 & _pid=$!
echo tooltip: $"Alarm clock was set to ${COUNTDOWN%"|"*} minutes \nand notifiers at $TASK1!" >&3
echo "action:quit" >&3
echo "menu:About!yad --about!gtk-info|Quit!quit!gtk-exit" >&3
echo "icon:${ICON}" >&3

wait $_pid
[[ $? -eq 0 || $? -eq 252 ]] && rm $temp && exit

Offline

#13 2019-11-16 11:44:42

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

And I 'fixed' my versions internal beep and added --alarm switch (getting somehow messy code). Also removed 'flite' experiments.

So now one can:

beepmein 1            # to get internal beep (reminder)
beepmein --alarm 1    # to get mpv playing preconfigured sample and internal beep (alarm)

test-s:

beepmein --reaction "Reminder test"
beepmein --reaction --alarm "Alarm test" 

Last edited by brontosaurusrex (2019-11-16 12:52:13)

Offline

#14 2019-11-16 12:11:30

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

brontosaurusrex wrote:

And I 'fixed' my versions internal beep and added --alarm switch (getting somehow messy code).

So now one can:

beepmein 1            # to get internal beep (reminder)
beepmein --alarm 1    # to get mpv playing preconfigured sample and internal beep

test-s:

beepmein --reaction "Reminder test"
beepmein --reaction --alarm "Alarm test" 

Script is looking good.

I may record next sound alarm to mp3, but first need remember how to do that smile

for ((i=1; i<=10; i++)); do
      for ((c=1;c<=3;c++)); do
          timeout -s HUP  0.2 speaker-test -t sine -f 3000  > /dev/null 2>&1
          sleep 0.2
       done
       sleep 1
done

Last edited by misko_2083 (2019-11-16 12:17:10)

Offline

#15 2019-11-16 13:24:29

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

misko_2083 wrote:
for ((i=1; i<=10; i++)); do
      for ((c=1;c<=3;c++)); do
          timeout -s HUP  0.2 speaker-test -t sine -f 3000  > /dev/null 2>&1
          sleep 0.2
       done
       sleep 1
done

Nice and annoying at the same time smile

Offline

#16 2019-11-16 16:07:55

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

misko_2083 wrote:

...
There is a special command "quit".

quit   Exit the program. Middle click on icon also send quit command.

Return status is 0 when it's called, even with the right click menu.

timeout --preserve-status $TIMER yad --notification  --listen <&3 & _pid=$!
echo tooltip: $"Alarm clock was set to ${COUNTDOWN%"|"*} minutes \nand notifiers at $TASK1!" >&3
echo "action:quit" >&3
echo "menu:About!yad --about!gtk-info|Quit!quit!gtk-exit" >&3
echo "icon:${ICON}" >&3

wait $_pid
[[ $? -eq 0 || $? -eq 252 ]] && rm $temp && exit

I had tried the quit command, but it seems that the return codes test is the secret sauce! You are a yad ninja  kiss  big_smile


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#17 2019-11-16 22:05:02

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

brontosaurusrex wrote:

Nice and annoying at the same time smile

The more annoying the easier to get up. smile

@damo The time is incorrect

"Time now is $(date +"%H:%m")"

"m" is for month, "M" for minutes.
Also the script continues after coundown dialog is closed, but that's also easy to fix (need to check for 252 return code).

I was thinking about displaying the current time in the dialog.
One way is to use wmctrl to change the title and the other one in to use the paned dialog.
https://i.imgur.com/NcnvZxH.gif
Which one is better?

Offline

#18 2019-11-16 22:33:23

Naik
Member
From: Lipsia
Registered: 2015-10-03
Posts: 186

Re: Alarm clock scripts

^ I'd vote for the first one. Can you tell me (us) how you set this window-title ?

naik --greetz


"Kaum macht [Mensch]* es richtig, funktioniert es sofort!"
BL-Kitchen on GitHub

Offline

#19 2019-11-16 22:45:44

misko_2083
Member
Registered: 2016-05-24
Posts: 252

Re: Alarm clock scripts

Sure.
First the window class is set.
That is used to find the window XID.

The function is called before yad dialog is launched.
Then the loop changes the title until the window is closed.

#!/bin/bash
win_class="some_class"

function change_title {
declare 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
}

change_title &

yad --class="${win_class}" --title="This will change" --width=500

Full script:

#!/bin/bash
#
# Alarm clock for PCLinuxOS
#
# Don't miss important times and events. Turn your computer 
# into the perfect wake up system. Set the alarm and get the 
# Pizza out of the oven in perfect time.
#
# Author: D.M-Wilhelm (Leiche)
# Email: meisssw01 at gmail.com
# Licence: GPL
# First build: May Wed 11 2011
# Last build: Jul Sun 10 2011
# fixed icon display in systray, move zenity,
# based now on yad.
#
Encoding=UTF-8
#
# i18n - Internationalization - Internationalisierung
#
export TEXTDOMAIN=alert_clock
export TEXTDOMAINDIR="/usr/share/locale"
#
# define some variables - Definierung einiger Variablen 
#
TITLE="Alarm Clock"
ICON="/usr/share/icons/Paper/48x48/apps/alarm-clock.png"
win_class="timer_class"

#--------------------
# change title to current time
#--------------------
function change_title {
declare 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
}

#--------------------
# question - Frage
#--------------------
function menu {

change_title &

COUNTDOWN=$(yad --class="${win_class}" --title="$TITLE : $(date '+%T')" \
            --button="Change alarm sound:2" \
            --button="Test:3" \
            --button="gtk-ok:0" \
            --button="gtk-close:1" \
            --form  --field "Enter minutes until alarm...":NUM  "1!1..10000")

ret=$?

[[ $ret -eq 1 ||  $ret -eq 252 ]] && exit 0

#--------------------
#change sound - Sound ändern
#--------------------
if [[ $ret -eq 2 ]]; then
    CHANGE=$(yad --title="$TITLE" --window-icon=$ICON \
        --file --width=600 --height=500 \
        --text=$"\n\t<b>Choose your own audio file as alert!</b>\n")
        if [ -z "$CHANGE" ];then 
        exec alert_clock
        exit 0
        else
        mkdir $HOME/.config/alert-clock
        rm -rf $HOME/.config/alert-clock/alert sleep 1
        ln -s "$CHANGE" $HOME/.config/alert-clock/alert
        yad --title $"$TITLE" \
            --button="gtk-ok:0" \
            --width 300 \
            --window-icon=$ICON \
            --text=$"Your own sound is set!!"
        fi
menu        
fi
#--------------------
#Test sound - Klang testen
#--------------------
if [[ $ret -eq 3 ]]; then
    if [ -f $HOME/.config/alert-clock/alert ]; then
    SOUND="$HOME/.config/alert-clock/alert"
    else
    SOUND='/usr/share/alert_clock/alarm.ogg'
    fi
mpv "$SOUND" | yad --title $"$TITLE" \
                 --button="gtk-ok:0" \
                 --width 300 \
                 --window-icon=$ICON \
                 --text=$"Exit sound test!!"
killall mpv
menu                 
fi
}
menu
#--------------------
# progress - Prozess
#--------------------
if [ "$COUNTDOWN" = "" ];then
exit
else

echo you enter "${COUNTDOWN%"|"*}" minutes
TIMER=$(echo $((${COUNTDOWN%"|"*}*60)))
TASK1=$(date -s "+$TIMER seconds" 2>/dev/null | cut -d " " -f4)
temp=$(mktemp -u --tmpdir alarm.XXXXXXXX)
mkfifo $temp

exec 3<> $temp

timeout --preserve-status $TIMER yad --notification  --listen <&3 & _pid=$!
echo tooltip: $"Alarm clock was set to ${COUNTDOWN%"|"*} minutes \nand notifiers at $TASK1!" >&3
echo "action:quit" >&3
echo "menu:About!yad --about!gtk-info|Quit!quit!gtk-exit" >&3
echo "icon:${ICON}" >&3
echo "visible:true" >&3

wait $_pid
[[ $? -eq 0 || $? -eq 252 ]] && rm $temp && exit

exec 3>&-
#--------------------
# check wich sound - auf Audio prüfen
#--------------------
if [ -f $HOME/.config/alert-clock/alert ]; then
    SOUND="$HOME/.config/alert-clock/alert"
    else
    SOUND='/usr/share/alert_clock/alarm.ogg'
fi
#--------------------
# alert output - Alarm Ausgabe
#--------------------
(mpv "$SOUND") | yad --title $"$TITLE" \
                 --button="gtk-ok:0" \
                 --width 300 --image=$ICON \
                 --window-icon=$ICON \
                 --text=$"<b>Time is over!!</b>"
                 exit;
fi
exit

@Damo check out my avatar smile

Offline

#20 2019-11-16 22:59:21

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

misko_2083 wrote:

...
@damo The time is incorrect

"Time now is $(date +"%H:%m")"

"m" is for month, "M" for minutes.
...

Yes I caught that, and I'm now using

%R     24-hour hour and minute; same as %H:%M

I was thinking about displaying the current time in the dialog.
One way is to use wmctrl to change the title and the other one in to use the paned dialog.
https://i.imgur.com/NcnvZxH.gif
Which one is better?

The first is nicer smile

----------------------------------------------------
I've done some tidying and polishing, and included a notify-send option for the notification as well. There is a minimum value of 1 sec for the entry box, since a val of zero makes no sense.

yad-alarm4.jpg
yad-alarm-tooltip.jpg

#!/bin/bash
#
# Alarm clock script using YAD dialog
#
# Author: D.M-Wilhelm (Leiche)
# Email: meisssw01 at gmail.com
# Licence: GPL
#
# Updated and tweaked by @misko_2083 and @damo, of the Bunsenlabs community
# November 2019
#
########################################################################
Encoding=UTF-8
#
# i18n - Internationalization
export TEXTDOMAIN=alert_clock
export TEXTDOMAINDIR="/usr/share/locale"
#
# define some variables
#
TITLE="Alarm Clock"
ICON="/usr/share/icons/Paper/48x48/apps/alarm-clock.png"
SOUNDFILE="/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga"

### main dialog ###
function menu {
COUNTDOWN=$(yad --form --align=right \
            --text "\n\t\t\tTime now is <span><big><b>$(date +"%R")</b></big></span>" \
            --field "\t\t\tEnter minutes until alarm...":NUM  1!1..12000!1 \
            --title="$TITLE" --window-icon=$ICON \
            --image=$ICON \
            --button="Change alarm sound:2" \
            --button="Test:3" \
            --button="gtk-ok:0" \
            --button="gtk-cancel:1" \
           )
ret=$?
COUNTDOWN="${COUNTDOWN%"|"*}"

[[ $ret -eq 1 ]] && exit 0
#
### Change sound dialog ###
#
if [[ $ret -eq 2 ]]; then
    CHANGE=$(yad --title="$TITLE" --window-icon=$ICON \
        --file --width=600 --height=500 \
        --filename="/usr/share/sounds/" \ 
        --text="\n\t<b>Choose an audio file for the alert</b>\n") 2>/dev/null

        if [ -z "$CHANGE" ];then 
            exec alert_clock 2>/dev/null
            exit 0
        else
            mkdir -p "$HOME/.config/alert-clock"
            rm -rf "$HOME/.config/alert-clock/alert"
            sleep 1
            ln -s "$CHANGE" "$HOME/.config/alert-clock/alert"
            yad --title "$TITLE" \
                --button="gtk-ok:0" \
                --width 300 \
                --window-icon=$ICON \
                --text="Your own sound is set"
        fi
    menu        
fi
#
### Test sound dialog ###
#
if [[ $ret -eq 3 ]]; then
    if [ -f $HOME/.config/alert-clock/alert ]; then
        SOUND="$HOME/.config/alert-clock/alert"
    else
        SOUND='/usr/share/alert_clock/alarm.ogg'
    fi
    mpv "$SOUND" | yad --title "$TITLE" \
                     --button="gtk-ok:0" \
                     --width 300 \
                     --window-icon=$ICON \
                     --text="...Exit sound test"
    killall mpv
    menu                 
fi
}
menu

[[ "$COUNTDOWN" == 1 ]] && MINS="minute" || MINS="minutes"

if [ -z "$COUNTDOWN" ];then
    exit
else
    echo You entered "$COUNTDOWN $MINS"
    TIMER=$(echo $((COUNTDOWN*60)))
    TASK1=$(date -s "+$TIMER seconds" 2>/dev/null | cut -d " " -f4)
    temp=$(mktemp -u --tmpdir alarm.XXXXXXXX)
    
    mkfifo $temp
    
    exec 3<> $temp
    
    timeout --preserve-status $TIMER yad --notification  --listen <&3 & _pid=$!
    echo tooltip: "\nAlarm clock was set to <span><big><b>$COUNTDOWN</b></big></span> $MINS \
        \n\nAlarm will be at <span><big><b>$TASK1</b></big></span> \
        \n\nLMB or MMB to quit, RMB for menu" >&3
    echo "action:quit" >&3
    echo "menu:About!yad --about!gtk-info|Quit!quit!gtk-exit" >&3
    echo "icon:${ICON}" >&3
    
    wait $_pid
    [[ $? -eq 0 || $? -eq 252 ]] && rm $temp && exit
    
    rm $temp
    exec 3>&-
    
    #check which sound
    #
    if [ -f $HOME/.config/alert-clock/alert ]; then
        SOUND="$HOME/.config/alert-clock/alert"
    else
        SOUND="$SOUNDFILE"
    fi
    #
    #alert output   Comment/Uncomment choice below...
    #
    ### Using YAD ###
    #(mpv "$SOUND") | yad --title "$TITLE" --undecorated \
                     #--no-buttons --sticky --escape-ok \
                     #--width 300 --image=$ICON \
                     #--window-icon="$ICON" \
                     #--timeout=10 \
                     #--text="\n\t<span><big><b>Time is up!</b></big></span>"
                     #exit;

    ### Using notify-send ###
    mpv "$SOUND" &
    notify-send -t 10000 -i "$ICON" "Time is up! "
    exit
    ###
fi

exit

Last edited by damo (2019-11-16 23:39:14)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#21 2019-11-16 23:00:27

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

misko_2083 wrote:

@Damo check out my avatar smile

Ninjaaaa big_smile


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

#22 2019-11-17 00:30:53

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

misko_2083 wrote:

The more annoying the easier to get up. smile

I added it as --alarm fail-safe if you don't mind?

Loud thinkering

Not sure if its the correct fail-safe behavior thought.

if [[ -f "$alarmSample" ]] && command -v mpv >/dev/null 2>&1 ; then
    mpv --no-resume-playback --no-video "$alarmSample"
else    
    alarmfailsafe
fi

because it appears I don't want

mpv --no-resume-playback --no-video "$alarmSample" ||  alarmfailsafe

since that will jump to alarmfailsafe in case of users 'killall mpv'. Unless I invent some sort of trap

trap 'kill $(jobs -p) >/dev/null 2>&1' EXIT

and user may now 'killall beepmein' to stop mpv playback and/or internal beep-ing.

end loud thinkering, and uploaded the latest version with 'trap' inside.

Sox experiment, example from man

/usr/bin/play -n synth pl G2 pl B2 pl D3 pl G3 pl D4 pl G4 \
delay 0 .05 .1 .15 .2 .25 remix - fade 0 4 .1 norm -1 > /dev/null 2>&1

Last edited by brontosaurusrex (2019-11-17 03:30:36)

Offline

#23 2019-11-17 03:21:41

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 6,081
Website

Re: Alarm clock scripts

This all looks very promising!

One request: can we drop the mpv dependency? It's not in BL by default. Just to play a sound file, any media player would work, no? So substitute bl-media-player?

OTOH if you don't want a big bloated GUI coming up just to play a sound, then I think aplay should be on every system, and can play a wav file. If the sound's not too long - or can be repeated - then the file won't be that big.


John
--------------------
( a boring Japan blog, idle Twitterings and GitStuff )
In case you forget, the rules.

Offline

#24 2019-11-17 03:38:44

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 1,932
Website

Re: Alarm clock scripts

@johnraff,

From what I gathered so far (and i can only talk about my script)

- 'at' event seems to fail when x stuff (gui) is supposed to launch (hopefully alarmfailsafe fixes that to some amount), so if bl-media-player presents a gui, i guess that will fail as well
- aplay will happily play mp3 file as well (as some sort of white noise)
- I guess the chain could be mpv || cvlc || someFailSafe internal beep

Last edited by brontosaurusrex (2019-11-17 03:39:44)

Offline

#25 2019-11-17 04:00:24

damo
....moderator....
Registered: 2015-08-20
Posts: 5,271

Re: Alarm clock scripts

johnraff wrote:

This all looks very promising!

One request: can we drop the mpv dependency? It's not in BL by default. Just to play a sound file, any media player would work, no? So substitute bl-media-player?

OTOH if you don't want a big bloated GUI coming up just to play a sound, then I think aplay should be on every system, and can play a wav file. If the sound's not too long - or can be repeated - then the file won't be that big.

I've just tried, and the script as-is doesn't show a gui with mpv - the sound just plays.

No gui with...

mpv "$SOUND"

But using bl-media-player (which for me links to bl-mpv) it does. Is that because it has --profile= bl-pseudo-gui?

And aplay doesn't play all formats sad

EDIT: The YAD file dialog can have filters to only display certain filetypes. Maybe that can be used so that only aplay-compatible soundfiles are used?

Last edited by damo (2019-11-17 04:07:17)


Be Excellent to Each Other...

FORUM RULES and posting guidelines «» Help page for forum post formatting
Artwork on DeviantArt  «» BunsenLabs on DeviantArt

Online

Board footer

Powered by FluxBB