LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   This should be a really easy task. (https://www.linuxquestions.org/questions/programming-9/this-should-be-a-really-easy-task-4175602637/)

d_K 03-27-2017 10:46 AM

This should be a really easy task.
 
On xfce, I'm looking to play a custom sound whenever a notification pops up. Here's the pseudocode:

Code:

while (true){
if [notify-send]
  /usr/bin/play -q ~/sounds/notification.wav
}

(sox is required for the command "play".)

Ru1138 03-27-2017 10:58 AM

Quote:

Originally Posted by d_K (Post 5688848)
On xfce, I'm looking to play a custom sound whenever a notification pops up. Here's the pseudocode:

Code:

while (true){
if [notify-send]
  /usr/bin/play -q ~/sounds/notification.wav
}

(sox is required for the command "play".)

I found this via Google: https://forum.xfce.org/viewtopic.php?id=8618

It doesn't directly apply to your issue (or does it?), but it may give you a few things to check.

d_K 03-27-2017 11:03 AM

Quote:

Originally Posted by Ru1138 (Post 5688854)
I found this via Google: https://forum.xfce.org/viewtopic.php?id=8618

It doesn't directly apply to your issue (or does it?), but it may give you a few things to check.

notifyd doesn't support system sounds. There's requests for it, but the devs haven't gotten to them yet apparently. For now I'm looking for a theoretically easy workaround.

Ru1138 03-27-2017 11:08 AM

Quote:

Originally Posted by d_K (Post 5688856)
notifyd doesn't support system sounds. There's requests for it, but the devs haven't gotten to them yet apparently. For now I'm looking for a theoretically easy workaround.

Okay. I don't really know what else to do. Best of luck on finding solutions though! :)

schneidz 03-27-2017 11:31 AM

this seems related
Code:

[schneidz@hyper ~]$ cat ./egg.ksh
#!/bin/bash
# Filename: progbar-timer.sh
# Version: 110212
# Author: robz
# Improved from the "Egg Timer" script, a countdown timer with progress bar.
# This one has an indication of time remaining provided by Zenity's progress
# bar function. As usual you'll need to find a sound and icon for the variables
# below, you might find the icon variable is correct, check the directory.

ICON=/usr/share/app-install/icons/kalarm.png              # Existing icon?
SOUND=/home/schneidz/music/Finding-Forever/01-Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro--Intro.mp3                              # Your sound pref.

COUNT=$(zenity --title "Egg Timer" --window-icon $ICON --text "No decimals"\
    --entry-text "eg. 10s or 5m or 2h" --entry)          # Input dialogue.
if [ $? = 1 ]; then exit $?; fi

# Determine number of seconds to count down from depending on input suffix.
case "${COUNT: -1}" in
    "S" | "s" ) COUNT=$(echo $COUNT | sed -s "s/[Ss]//") ;;
    "M" | "m" ) COUNT=$(echo $COUNT | sed -s "s/[Mm]//"); ((COUNT*=60)) ;;
    "H" | "h" ) COUNT=$(echo $COUNT | sed -s "s/[Hh]//"); ((COUNT*=3600)) ;;
    *        ) zenity --error --text "<span color=\"red\"><b>\
    \nUse the form of 10s or 5m or 2h\nNo decimals allowed either.</b></span>"
    sh -c "$0"                                            # On error restart.
    exit ;;
esac

START=$COUNT                                              # Set a start point.

until [ "$COUNT" -eq "0" ]; do                            # Countdown loop.
    ((COUNT-=1))                                          # Decrement seconds.
    PERCENT=$((100-100*COUNT/START))                      # Calc percentage.
    echo "#Time remaining$(echo "obase=60;$COUNT" | bc)"  # Convert to H:M:S.
    echo $PERCENT                                        # Outut for progbar.
    sleep 1
done | zenity --title "Egg Timer" --progress --percentage=0 --text=""\
    --window-icon=$ICON --auto-close                      # Progbar/time left.
if [ $? = 1 ]; then exit $?; fi
notify-send -i $ICON "Egg Timer > ## TIMES UP ##"        # Attention finish!
/usr/bin/canberra-gtk-play --volume 4 -f $SOUND          # Ding-dong finish!
zenity --notification --window-icon="$ICON"\
    --text "Egg Timer > ## TIMES UP ##"                  # Indicate finished!


d_K 03-27-2017 11:37 AM

Quote:

Originally Posted by schneidz (Post 5688864)
this seems related
Code:

notify-send -i $ICON "Egg Timer > ## TIMES UP ##"        # Attention finish!
/usr/bin/canberra-gtk-play --volume 4 -f $SOUND          # Ding-dong finish!


Looks to be unrelated, as you can see there the canberra sound just follows another line that just happens to be after notify-send'ing a notification. There's no, if you like, "system event checking" going on.


All times are GMT -5. The time now is 05:49 PM.