You are not logged in.

#41 2020-01-28 19:57:54

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: Alarm clock scripts

^Nice, so this should basically echo js console.log back to terminal/stdsomething?
(Can't make it work for some reason (./openwithyad), not getting anything back to term).

Last edited by brontosaurusrex (2020-01-28 20:39:01)

Online

#42 2020-01-28 22:59:06

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: Alarm clock scripts

yad --version
5.0 (GTK+ 3.24.5

But i build this, since Debian Buster is not having webkit enabled by default as it seems? The nonbufered version not working either. Must be a custom yad issue...

Last edited by brontosaurusrex (2020-01-28 23:01:35)

Online

#43 2020-01-29 15:59:37

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Re: Alarm clock scripts

It doesn't work.

Online

#44 2020-01-29 19:46:41

brontosaurusrex
Middle Office
Registered: 2015-09-29
Posts: 2,746

Online

#45 2020-04-18 05:54:22

johnraff
nullglob
From: Nagoya, Japan
Registered: 2015-09-09
Posts: 12,652
Website

Re: Alarm clock scripts

Possible alternative to 'at' for those who can live with systemd is 'systemd-run'.
The man page is not so easy to understand, but eg this:
https://www.linux-magazine.com/Issues/2 … eztoc0_0_3
Web-searching might bring up more stuff.
Anyway this worked:

systemd-run --user --on-active=1m -E DISPLAY=:0.0 /home/john/bin/beepmein --reaction test

Although the --on-active time seemed a bit slack. I haven't worked on this at all though...


...elevator in the Brain Hotel, broken down but just as well...
( a boring Japan blog (currently paused), now on Bluesky, there's also some GitStuff )

Introduction to the Bunsenlabs Boron Desktop

Offline

#46 2020-11-30 12:32:07

jerry3904
New Member
Registered: 2020-11-30
Posts: 2

Re: Alarm clock scripts

Hi. I'm the Lead for the Fluxbox version of MX Linux, and wanted to tell the Community how much we liked and appreciated the timer posted by @damo at the beginning of this thread and developed further by contributions from @misko_2083 and others.

We have just finished developing it further and it now forms part of our optional mxfb-goodies (https://github.com/MX-Linux/mxfb-goodies). I believe that with minor changes to icon and alarm sound this will work for you, so am posting the new script in case you are interested. BTW: the localization for that is in progress ATM and should be up within a week when we release the new package.

#!/bin/bash
#!/bin/bash
#
# Timer script using YAD dialog
#
# Author: D.M-Wilhelm (Leiche)
# Email: meisssw01 at gmail.com
# Licence: GPL
# Original date: 2011
#
# Updated and tweaked by @misko_2083 and @damo, of the bunsenlabs community
# November 2019
#
# Modified and elaborated by MX Linux Devs for use with MX-Fluxbox
# November 2020 
# The sound file used here is located in the components folder
########################################################################
Encoding=UTF-8
#
# i18n - Internationalization
export TEXTDOMAIN=mxfb-timer
export TEXTDOMAINDIR="/usr/share/locale"

TITLE=$"MXFB Timer"
DIR1=$"Enter local time"
DIR2=$"or number and unit"
DIR3=$"Click \"Check...\" button to confirm time and date are correct"
DIR4=$"Click systemtray icon to cancel"
DIR5=$"Choose an audio file for the alert"
DIR6=$"Alarm sound now in use is"
DIR7=$"You need to choose a sound file"
DIR8=$"Exit sound test"
DIR9=$"You entered"
DIR10=$"Alarm clock was set to"
DIR11=$"Alarm will be at  "
DIR12=$"Left-click to quit, right-click for menu"
DIR13=$"Time is up"
MSG10=$"Setting"
#MSG11=$"Alarm will be at"
#MSG12=$"Left-click to quit, right-click for menu"
#MSG13=$"Time is up!"

QUIT=$"Quit"

TIME1=$"minutes"
TIME2=$"hours"
TIME3=$"days"
BUTTON1=$"Change sound"
BUTTON2=$"Test sound"
FIELD1=$"Enter alarm time"
FIELD2=$"Check time and date"


#
# define some variables
#
TITLE="MXFB Timer"
#ICON="/usr/share/icons/Moka/64x64/apps/time-admin.png"
ICON="/usr/share/icons/Papirus/64x64/apps/alarm-clock.svg"
#ICON="/usr/share/icons/Paper/48x48/apps/alarm-clock.png"
ICON2="/usr/share/icons/mxflux.png"
SOUNDFILE="/usr/share/sounds/bleep.wav"
#SOUNDFILE="/usr/share/sounds/freedesktop/stereo/alarm-clock-elapsed.oga"
#SOUNDFILE=/usr/share/sounds/Fresh_and_Clean/stereo/phone-incoming-call.ogg
export SOUNDFILE
# Choose whether to use YAD dialog or system notification for Alarm alert
ALERT="YAD_ALERT"
#ALERT="SYSTEM_ALERT"

win_class="timer_class"

### Check default icon and sound file ###
[[ ! -f "$ICON" ]] && echo "$ICON not found"
[[ ! -f "$SOUNDFILE" ]] && echo "Default soundfile, $SOUNDFILE, not found"

### Test for mpv player
#if ! hash mpv; then
#    echo "$0: mpv binary is missing. Please issue 'sudo apt-get install mpv'." >&2
#    exit 1
#fi

PLAYERLIST=(
   paplay
   mpv
   cvlc
)

export PLAY=""
for P in ${PLAYERLIST[@]}; do
    which $P >/dev/null || continue
    case $P in
         paplay) PLAY="paplay"; break
              ;;
            mpv) PLAY="mpv --no-video"; break
              ;;
           cvlc) PLAY="cvlc --play-and-exit --no-loop --no-repeat"; break
              ;;
     esac   
done

echo "PLAYER=$PLAY"

function playsound {
    local sound
    if [ -f $HOME/.config/mxfb-timer/alert ]; then
          sound=$(readlink -e "$HOME/.config/mxfb-timer/alert")
    else
          sound="$SOUNDFILE"
    fi
 
    echo "Running: playsound" >&2
    echo "$PLAY $sound" >&2
    $PLAY "$sound"
}
export -f playsound 
    	
 


# to transform entered allert time
# in addtion to date's --date="STRING"
# allowed formats 
# "NMMM"  or "N MMM"  or "+NMMM" or "+N MMM"
# where N is a number and MMM any out of: minutes, hours, days, weeks, month, years
# MMM can be abriavated down to one letter, except "month" down to "mo" 
# e.g.:
#  "1" = "+1 minute"
#  "1m +2d +3w 4mo" = "+1 minutes +2 days +3 weeks +4 month"
function transform {
	local alert="$1"
	echo "$alert" | sed -r \
	 -e '/[:-]/b' \
	 -e 's/[+]?([0-9]+)$/+\1 minute/' \
	 -e 's/[+]?([0-9]+)[[:space:]]*m(i(n(u(t(e(s)?)?)?)?)?)?[[:space:]]*/+\1 minutes /' \
	 -e 's/[+]?([0-9]+)[[:space:]]*h(o(u(r(s)?)?)?)?[[:space:]]*/+\1 hours /' \
	 -e 's/[+]?([0-9]+)[[:space:]]*d(a(y(s)?)?)?[[:space:]]*/+\1 days /' \
	 -e 's/[+]?([0-9]+)[[:space:]]*w(e(e(k(s)?)?)?)?[[:space:]]*/+\1 weeks /' \
	 -e 's/[+]?([0-9]+)[[:space:]]*mo(n(t(h)?)?)?[[:space:]]*/+\1 month /' \
	 -e 's/[+]?([0-9]+)[[:space:]]*y(e(a(r(s)?)?)?)?[[:space:]]*/+\1 year /'
}	
export -f transform	
	
	
	
	
function get_alert {
    local mode="$1"
    local time_entered="$2"
    local time_transformed=$(transform "$time_entered")
    local alert_min=""
    local alert_time="<invalid time>"
    echo "time_entered=$1" >&2
    echo "time_transformed=$time_transformed" >&2
    if [ -n "$time_transformed" ]; then
	    local sec_ent="$(date --date="$time_transformed" '+%s' 2>/dev/null)"
	    local sec_now="$(date '+%s')"
	    echo "sec_ent=$sec_ent" >&2
	    echo "sec_now=$sec_now" >&2
	    alert_min=$(( ($sec_ent - $sec_now)/60 ))
	    echo "alert_min=$alert_min" >&2
	    
	    if [ $alert_min -lt 1 ]; then
	       if [ $alert_min -gt $(( -24 * 60 )) ]; then
	          alert_min=$(( $alert_min +  24 * 60  ))
	          alert_time=$(date --date="+$alert_min minutes" '+%X %x')
	       else
	          alert_time="<invalid time>"
	          alert_min=""
	       fi
	    else
	       alert_time=$(date --date="+$alert_min minutes" '+%X %x')
	    fi
    fi
    echo "alert_time=$alert_time" >&2

	case "$mode" in
	      time) echo "$alert_time"
	          ;;
	      min*) echo "$alert_min"
	          ;;
	         *) echo "<invalid time>"    
	          ;;
	esac
	
}
export  -f get_alert


### main dialog ###
function menu {
    #change_title &
    
    COUNTDOWN=$(/bin/yad --class="${win_class}" \
					--title="$TITLE     ($(date '+%D -- %R'))" \
                    --window-icon="$ICON2" --center \
                    --text "
                    <b><i>1) $DIR1 (9:15pm, 13:50, 12am, etc.)  \n
                         $DIR2 (\"3 $TIME1\", \"12 $TIME2\", \"2$TIME2 + 30$TIME1\", etc.) \n
                    2) $DIR3 \n
                    3) $DIR4</i></b>
                    " \
                    --image="$ICON" \
                    --borders=15 \
                    --button="$BUTTON1:2" \
                    --button="$BUTTON2:bash -c 'playsound $SOUNDFILE'" \
                    --button="gtk-cancel:1" \
                    --button="gtk-ok:0" \
                    --height=180 \
                    --form  \
                    --align=center \
					--field "$FIELD1 ... :LBL" ""  \
					--field "$FIELD2 ...:FBTN" '@bash -c "echo 4:$(get_alert time %3)"' \
					--field "" \
					--field ' :RO' ""  "<not set>" \
					--columns=2 \
					)

    ret=$?
	IFS='|' read -r _ _ COUNTDOWN _ <<<$COUNTDOWN
    COUNTDOWN=$(get_alert minutes $COUNTDOWN)
   
    [[ $ret -eq 1 ]] && exit 0
    #
    ### Change sound dialog ###
    #
    if [[ $ret -eq 2 ]]; then
        CHANGE=$(yad --title="$TITLE" --window-icon=$ICON2 \
            --file --width=600 --height=500 --center \
            --button="gtk-ok:0" --button="gtk-cancel:1" \
            --filename="/usr/share/sounds/" \
            --text="\n\t<b>$DIR5</b>\n") 
    
            if [ -z "$CHANGE" ];then 
                menu
            else
                # check soundfile exists
                if [ -f "$CHANGE" ];then
                    mkdir -p "$HOME/.config/mxfb-timer"
                    rm -rf "$HOME/.config/mxfb-timer/alert"
                    sleep 1
                    ln -s "$CHANGE" "$HOME/.config/mxfb-timer/alert"
                    yad --title "$TITLE" \
                        --button="gtk-ok:0" \
                        --width 300 --borders=15 --center \
                        --window-icon="$ICON2" \
                        --text="\n$DIR6:\n\n<i>$CHANGE</i>"
                else
                    yad --title "$TITLE" \
                         --button="gtk-ok:0" \
                         --borders=15 --center \
                         --window-icon="$ICON2" --image-on-top \
                         --image="gtk-dialog-warning" \
                         --text="\t<big>$DIR7</big>"
    
                    exec mxfb-timer
                    exit
                fi
            fi
        menu        
    fi
    #
    ### Test sound dialog ###
    #
    if [[ $ret -eq 3 ]]; then
        if [ -f $HOME/.config/mxfb-timer/alert ]; then
            SOUND="$HOME/.config/mxfb-timer/alert"
        else
            SOUND="$SOUNDFILE"
        fi
        echo $PLAY "$SOUND"
        timeout 10 $PLAY "$SOUND"
         
        #$PLAY "$SOUND" | yad --title "$TITLE" \
        #                 --button="gtk-ok:0" \
        #                 --width 300 --center --borders=15 \
        #                 --window-icon="$ICON2" \
        #                 --text="\n\t...$DIR8"
#        killall mpv
         #pkill -xf "mpv --no-video $SOUND"
         #pkill -xf "$PLAY $SOUND"

        menu                 
    fi
}
menu
echo "COUNTDOWN: $COUNTDOWN"
[[ "$COUNTDOWN" == 1 ]] && MINS="minute" || MINS="minutes"

if [ -z "$COUNTDOWN" ];then
    exit
else
    echo $DIR9 "$COUNTDOWN $MINS"
    TIMER=$(echo $((COUNTDOWN*60)))
    TASK1=$(date --date="+$TIMER seconds" 2>/dev/null | cut -d " " -f5)
    temp=$(mktemp -u --tmpdir alarm.XXXXXXXX)
    
    mkfifo $temp
    
exec 3<> $temp

# TOOLTIP="\nAlarm clock was set to <big><b>$COUNTDOWN</b></big> $MINS \
#        \n\nAlarm will be at  <big><b>$TASK1</b></big> \
#        \n\nLeft-click to quit, right-click for menu"


COUNTDOWN_BIG="<big><b>$COUNTDOWN</b></big>"
TASK_BIG="<big><b>$TASK1</b></big>"

T_LINE_1="$DIR10 $COUNTDOWN_BIG $MINS"
T_LINE_2="$DIR11 $TASK_BIG"
T_LINE_3="$DIR12"

M_LINE_1="$DIR10 $COUNTDOWN $MINS"
M_LINE_2="$DIR11 $TASK1"

TOOLTIP="\n"
TOOLTIP+="$T_LINE_1\n\n"
TOOLTIP+="$T_LINE_2\n\n"
TOOLTIP+="$T_LINE_3"

timeout --preserve-status ${TIMER}m \
   yad --notification  --listen <&3 & _pid=$!
echo tooltip: "$TOOLTIP" >&3
echo "action:quit" >&3
echo 'menu:'"$M_LINE_1"'!true|'"$M_LINE_2"'!true|'"$QUIT"'!quit!gtk-quit' >&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/mxfb-timer/alert" ]; then
        SOUND="$HOME/.config/mxfb-timer/alert"
    else
        SOUND="$SOUNDFILE"  # use default soundfile
    fi

    if [ "$ALERT" == "YAD_ALERT" ];then
        ### Using YAD ##########
        ($PLAY "$SOUND") | yad --title "$TITLE" --undecorated --center \
                         --no-buttons --sticky --escape-ok --on-top \
                         --width 300 --image="$ICON" \
                         --window-icon="$ICON2" \
                         --borders=15 \
                         --timeout=3 \
                         --text="\n\t<big><b>$DIR13!</b></big>"
                         exit
    else
        ### Using notify-send ###
        mpv --no-video "$SOUND" &
        notify-send -i "$ICON" "$DIR13! "
        exit
    fi
fi

exit

Offline

#47 2020-12-02 14:56:56

jerry3904
New Member
Registered: 2020-11-30
Posts: 2

Re: Alarm clock scripts

Glad to *see* you again, misko! Thanks for the reference--I wasn't aware of that version and will take a look the next time the mood hits me to look at this.

I should point out for everybody here that misko helped us greatly in our effort to resuscitate and rework iDesk and its GUI, which now functions well and is much more accessible to regular users.

Offline

Board footer

Powered by FluxBB