How can I play a sound when script execution is ready?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
37
down vote

favorite
9












I am executing every now and then some python scripts which take quite long to execute.



I execute them like this:
$ time python MyScript.py



How can I play a sound as soon as the execution of the script is done?



I use Ubuntu 10.10 (Gnome desktop).










share|improve this question























  • Are you using bash or zsh? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using.
    – Mikel
    Mar 4 '11 at 23:06










  • $ echo $SHELL returns "/bin/bash"
    – Martin Thoma
    Mar 5 '11 at 20:39















up vote
37
down vote

favorite
9












I am executing every now and then some python scripts which take quite long to execute.



I execute them like this:
$ time python MyScript.py



How can I play a sound as soon as the execution of the script is done?



I use Ubuntu 10.10 (Gnome desktop).










share|improve this question























  • Are you using bash or zsh? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using.
    – Mikel
    Mar 4 '11 at 23:06










  • $ echo $SHELL returns "/bin/bash"
    – Martin Thoma
    Mar 5 '11 at 20:39













up vote
37
down vote

favorite
9









up vote
37
down vote

favorite
9






9





I am executing every now and then some python scripts which take quite long to execute.



I execute them like this:
$ time python MyScript.py



How can I play a sound as soon as the execution of the script is done?



I use Ubuntu 10.10 (Gnome desktop).










share|improve this question















I am executing every now and then some python scripts which take quite long to execute.



I execute them like this:
$ time python MyScript.py



How can I play a sound as soon as the execution of the script is done?



I use Ubuntu 10.10 (Gnome desktop).







shell ubuntu audio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 4 '11 at 23:00









Gilles

514k12110211550




514k12110211550










asked Mar 4 '11 at 22:44









Martin Thoma

1,13231842




1,13231842











  • Are you using bash or zsh? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using.
    – Mikel
    Mar 4 '11 at 23:06










  • $ echo $SHELL returns "/bin/bash"
    – Martin Thoma
    Mar 5 '11 at 20:39

















  • Are you using bash or zsh? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using.
    – Mikel
    Mar 4 '11 at 23:06










  • $ echo $SHELL returns "/bin/bash"
    – Martin Thoma
    Mar 5 '11 at 20:39
















Are you using bash or zsh? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using.
– Mikel
Mar 4 '11 at 23:06




Are you using bash or zsh? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using.
– Mikel
Mar 4 '11 at 23:06












$ echo $SHELL returns "/bin/bash"
– Martin Thoma
Mar 5 '11 at 20:39





$ echo $SHELL returns "/bin/bash"
– Martin Thoma
Mar 5 '11 at 20:39











7 Answers
7






active

oldest

votes

















up vote
34
down vote



accepted










Append any command that plays a sound; this could be as simple as



$ time mycommand; printf '7'


or as complex as



$ time mycommand && paplay itworked.ogg || paplay bombed.ogg


(Commands assume pulseaudio is installed; substitute your sound player, which will depend on your desktop environment.)






share|improve this answer


















  • 5




    +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
    – Mikel
    Mar 4 '11 at 23:21






  • 3




    printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
    – Martin Thoma
    Mar 5 '11 at 20:43











  • printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
    – laggingreflex
    Sep 17 '14 at 23:20











  • @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
    – musiphil
    Nov 20 '14 at 18:31






  • 2




    @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
    – cprn
    Aug 24 '15 at 20:49

















up vote
9
down vote













Just pick a sound on your hard drive, and put a command to play it right after the command you're waiting on; they'll happen sequentially:



$ time python MyScript.py; mplayer ~/ScriptDone.wav


(You can use any player, naturally). I have a script called alertdone that plays a tone and shows an libnotify alert when run; I use it for exactly this occasion:



$ time python MyScript.py; alertdone "Done timing"


It's really simple, so if you want to make your own you can base it on this (mine requires notify-more, mplayer, and ~/tones/alert_1.wav though):



#!/bin/bash
message=$1:-"Finished working"
notify-more -t 10000 -i /usr/share/icons/gnome/32x32/actions/insert-object.png "Process Finished" "$message"
mplayer ~/tones/alert_1.wav





share|improve this answer
















  • 2




    notify-more or notify-send could indeed be useful alternatives to playing a sound.
    – Mikel
    Mar 4 '11 at 23:19










  • @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
    – Michael Mrozek♦
    Mar 4 '11 at 23:31

















up vote
8
down vote













time python MyScript.py; play /path/so/sound.ogg


play is a very basic (no UI) sound player from the sox Install sox http://bit.ly/software-small package. You can replace it by any other command-line-driven sound player.






share|improve this answer




















  • Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
    – Mikel
    Mar 4 '11 at 23:20







  • 1




    time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
    – Martin Thoma
    Mar 5 '11 at 20:46


















up vote
8
down vote













spd-say



sleep 2; spd-say 'get back to work'


Infinite loop with -w if you need extra motivation:



sleep 2; while true; do spd-say -w 'get back to work'; done


Pre-installed on 14.04 via package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?



Also add a popup



This combo is a life saver:



b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )


and then:



super-slow-command;b


If I'm somewhere in the room, I'll hear it and know that the long job is done.



Otherwise, I'll see the popup when I get back to my computer.



Related: https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux






share|improve this answer






















  • To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
    – dfarrell07
    Dec 13 '16 at 18:27


















up vote
3
down vote













You can also make this happen automatically.



I will show you how in zsh, then add info about bash.



The essence looks like this:



preexec()

starttime=$SECONDS


precmd()

if ((SECONDS - starttime >= 5)); then
aplay "sound.wav"
# or printf "b", or notify-send, or whatever
fi



You can also make it only do it if the program was Python, e.g.



preexec()

starttime=$SECONDS
case $3 in python*)
command_is_python=true;;
*)
command_is_python=false;;
esac


precmd()

if $command_is_python && ((SECONDS - starttime >= 5)); then
aplay "sound.wav"
# or printf "b", or notify-send, or whatever
fi



In bash, the best way is to download preexec.bash.txt and source it (e.g. . ~/preexec.bash.txt at the top of your ~/.bashrc, then the above (or something close to it) should work. (Not sure about the $3 bit to check if the command is Python.)



If you're using GNOME Terminal, I would also point you to Flashing GNOME Terminal. It's a patch I wrote that makes the terminal blink when a command is done, so you can Alt-Tab to something else, then it lets you know when it's done.






share|improve this answer





























    up vote
    0
    down vote













    Personally, I use my-script && notify-send "done". This sends a desktop notification, which on Linux Mint looks like this:



    enter image description here





    share








    New contributor




    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.
























      up vote
      -1
      down vote













      Any player can be used. I'm adding cvlc for completeness.






      share|improve this answer




















        Your Answer







        StackExchange.ready(function()
        var channelOptions =
        tags: "".split(" "),
        id: "106"
        ;
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function()
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled)
        StackExchange.using("snippets", function()
        createEditor();
        );

        else
        createEditor();

        );

        function createEditor()
        StackExchange.prepareEditor(
        heartbeatType: 'answer',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        );



        );













         

        draft saved


        draft discarded


















        StackExchange.ready(
        function ()
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f8607%2fhow-can-i-play-a-sound-when-script-execution-is-ready%23new-answer', 'question_page');

        );

        Post as a guest






























        7 Answers
        7






        active

        oldest

        votes








        7 Answers
        7






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        34
        down vote



        accepted










        Append any command that plays a sound; this could be as simple as



        $ time mycommand; printf '7'


        or as complex as



        $ time mycommand && paplay itworked.ogg || paplay bombed.ogg


        (Commands assume pulseaudio is installed; substitute your sound player, which will depend on your desktop environment.)






        share|improve this answer


















        • 5




          +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
          – Mikel
          Mar 4 '11 at 23:21






        • 3




          printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
          – Martin Thoma
          Mar 5 '11 at 20:43











        • printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
          – laggingreflex
          Sep 17 '14 at 23:20











        • @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
          – musiphil
          Nov 20 '14 at 18:31






        • 2




          @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
          – cprn
          Aug 24 '15 at 20:49














        up vote
        34
        down vote



        accepted










        Append any command that plays a sound; this could be as simple as



        $ time mycommand; printf '7'


        or as complex as



        $ time mycommand && paplay itworked.ogg || paplay bombed.ogg


        (Commands assume pulseaudio is installed; substitute your sound player, which will depend on your desktop environment.)






        share|improve this answer


















        • 5




          +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
          – Mikel
          Mar 4 '11 at 23:21






        • 3




          printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
          – Martin Thoma
          Mar 5 '11 at 20:43











        • printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
          – laggingreflex
          Sep 17 '14 at 23:20











        • @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
          – musiphil
          Nov 20 '14 at 18:31






        • 2




          @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
          – cprn
          Aug 24 '15 at 20:49












        up vote
        34
        down vote



        accepted







        up vote
        34
        down vote



        accepted






        Append any command that plays a sound; this could be as simple as



        $ time mycommand; printf '7'


        or as complex as



        $ time mycommand && paplay itworked.ogg || paplay bombed.ogg


        (Commands assume pulseaudio is installed; substitute your sound player, which will depend on your desktop environment.)






        share|improve this answer














        Append any command that plays a sound; this could be as simple as



        $ time mycommand; printf '7'


        or as complex as



        $ time mycommand && paplay itworked.ogg || paplay bombed.ogg


        (Commands assume pulseaudio is installed; substitute your sound player, which will depend on your desktop environment.)







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 5 '11 at 0:06

























        answered Mar 4 '11 at 23:05









        geekosaur

        22k25853




        22k25853







        • 5




          +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
          – Mikel
          Mar 4 '11 at 23:21






        • 3




          printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
          – Martin Thoma
          Mar 5 '11 at 20:43











        • printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
          – laggingreflex
          Sep 17 '14 at 23:20











        • @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
          – musiphil
          Nov 20 '14 at 18:31






        • 2




          @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
          – cprn
          Aug 24 '15 at 20:49












        • 5




          +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
          – Mikel
          Mar 4 '11 at 23:21






        • 3




          printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
          – Martin Thoma
          Mar 5 '11 at 20:43











        • printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
          – laggingreflex
          Sep 17 '14 at 23:20











        • @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
          – musiphil
          Nov 20 '14 at 18:31






        • 2




          @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
          – cprn
          Aug 24 '15 at 20:49







        5




        5




        +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
        – Mikel
        Mar 4 '11 at 23:21




        +1 paplay is probably the best command to use to play a sound on a "modern" Linux system.
        – Mikel
        Mar 4 '11 at 23:21




        3




        3




        printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
        – Martin Thoma
        Mar 5 '11 at 20:43





        printf '7' doesn't work for me, but this command worked as I wanted it time python MyScript.py -n 40 && paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg || paplay /usr/share/sounds/ubuntu/stereo/phone-outgoing-busy.ogg
        – Martin Thoma
        Mar 5 '11 at 20:43













        printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
        – laggingreflex
        Sep 17 '14 at 23:20





        printf '7' works for me (paplay doesn't; (git shell)) but it's just a very small bip. Are there more codes that make other sounds? I tried 6, 8 but they are some characters.
        – laggingreflex
        Sep 17 '14 at 23:20













        @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
        – musiphil
        Nov 20 '14 at 18:31




        @laggingreflex No, 7 (BEL) is usually the only character that possibly triggers a sound (see the Wikipedia article Control character); note that it may not always make a sound, either.
        – musiphil
        Nov 20 '14 at 18:31




        2




        2




        @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
        – cprn
        Aug 24 '15 at 20:49




        @laggingreflex You probably don't need this any more but just for laughs ;) for i in 1..30; do for j in 1..3; do printf '7'; sleep 0.12; done; sleep 0.4; done
        – cprn
        Aug 24 '15 at 20:49












        up vote
        9
        down vote













        Just pick a sound on your hard drive, and put a command to play it right after the command you're waiting on; they'll happen sequentially:



        $ time python MyScript.py; mplayer ~/ScriptDone.wav


        (You can use any player, naturally). I have a script called alertdone that plays a tone and shows an libnotify alert when run; I use it for exactly this occasion:



        $ time python MyScript.py; alertdone "Done timing"


        It's really simple, so if you want to make your own you can base it on this (mine requires notify-more, mplayer, and ~/tones/alert_1.wav though):



        #!/bin/bash
        message=$1:-"Finished working"
        notify-more -t 10000 -i /usr/share/icons/gnome/32x32/actions/insert-object.png "Process Finished" "$message"
        mplayer ~/tones/alert_1.wav





        share|improve this answer
















        • 2




          notify-more or notify-send could indeed be useful alternatives to playing a sound.
          – Mikel
          Mar 4 '11 at 23:19










        • @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
          – Michael Mrozek♦
          Mar 4 '11 at 23:31














        up vote
        9
        down vote













        Just pick a sound on your hard drive, and put a command to play it right after the command you're waiting on; they'll happen sequentially:



        $ time python MyScript.py; mplayer ~/ScriptDone.wav


        (You can use any player, naturally). I have a script called alertdone that plays a tone and shows an libnotify alert when run; I use it for exactly this occasion:



        $ time python MyScript.py; alertdone "Done timing"


        It's really simple, so if you want to make your own you can base it on this (mine requires notify-more, mplayer, and ~/tones/alert_1.wav though):



        #!/bin/bash
        message=$1:-"Finished working"
        notify-more -t 10000 -i /usr/share/icons/gnome/32x32/actions/insert-object.png "Process Finished" "$message"
        mplayer ~/tones/alert_1.wav





        share|improve this answer
















        • 2




          notify-more or notify-send could indeed be useful alternatives to playing a sound.
          – Mikel
          Mar 4 '11 at 23:19










        • @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
          – Michael Mrozek♦
          Mar 4 '11 at 23:31












        up vote
        9
        down vote










        up vote
        9
        down vote









        Just pick a sound on your hard drive, and put a command to play it right after the command you're waiting on; they'll happen sequentially:



        $ time python MyScript.py; mplayer ~/ScriptDone.wav


        (You can use any player, naturally). I have a script called alertdone that plays a tone and shows an libnotify alert when run; I use it for exactly this occasion:



        $ time python MyScript.py; alertdone "Done timing"


        It's really simple, so if you want to make your own you can base it on this (mine requires notify-more, mplayer, and ~/tones/alert_1.wav though):



        #!/bin/bash
        message=$1:-"Finished working"
        notify-more -t 10000 -i /usr/share/icons/gnome/32x32/actions/insert-object.png "Process Finished" "$message"
        mplayer ~/tones/alert_1.wav





        share|improve this answer












        Just pick a sound on your hard drive, and put a command to play it right after the command you're waiting on; they'll happen sequentially:



        $ time python MyScript.py; mplayer ~/ScriptDone.wav


        (You can use any player, naturally). I have a script called alertdone that plays a tone and shows an libnotify alert when run; I use it for exactly this occasion:



        $ time python MyScript.py; alertdone "Done timing"


        It's really simple, so if you want to make your own you can base it on this (mine requires notify-more, mplayer, and ~/tones/alert_1.wav though):



        #!/bin/bash
        message=$1:-"Finished working"
        notify-more -t 10000 -i /usr/share/icons/gnome/32x32/actions/insert-object.png "Process Finished" "$message"
        mplayer ~/tones/alert_1.wav






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 4 '11 at 23:03









        Michael Mrozek♦

        59.1k27186207




        59.1k27186207







        • 2




          notify-more or notify-send could indeed be useful alternatives to playing a sound.
          – Mikel
          Mar 4 '11 at 23:19










        • @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
          – Michael Mrozek♦
          Mar 4 '11 at 23:31












        • 2




          notify-more or notify-send could indeed be useful alternatives to playing a sound.
          – Mikel
          Mar 4 '11 at 23:19










        • @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
          – Michael Mrozek♦
          Mar 4 '11 at 23:31







        2




        2




        notify-more or notify-send could indeed be useful alternatives to playing a sound.
        – Mikel
        Mar 4 '11 at 23:19




        notify-more or notify-send could indeed be useful alternatives to playing a sound.
        – Mikel
        Mar 4 '11 at 23:19












        @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
        – Michael Mrozek♦
        Mar 4 '11 at 23:31




        @Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
        – Michael Mrozek♦
        Mar 4 '11 at 23:31










        up vote
        8
        down vote













        time python MyScript.py; play /path/so/sound.ogg


        play is a very basic (no UI) sound player from the sox Install sox http://bit.ly/software-small package. You can replace it by any other command-line-driven sound player.






        share|improve this answer




















        • Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
          – Mikel
          Mar 4 '11 at 23:20







        • 1




          time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
          – Martin Thoma
          Mar 5 '11 at 20:46















        up vote
        8
        down vote













        time python MyScript.py; play /path/so/sound.ogg


        play is a very basic (no UI) sound player from the sox Install sox http://bit.ly/software-small package. You can replace it by any other command-line-driven sound player.






        share|improve this answer




















        • Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
          – Mikel
          Mar 4 '11 at 23:20







        • 1




          time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
          – Martin Thoma
          Mar 5 '11 at 20:46













        up vote
        8
        down vote










        up vote
        8
        down vote









        time python MyScript.py; play /path/so/sound.ogg


        play is a very basic (no UI) sound player from the sox Install sox http://bit.ly/software-small package. You can replace it by any other command-line-driven sound player.






        share|improve this answer












        time python MyScript.py; play /path/so/sound.ogg


        play is a very basic (no UI) sound player from the sox Install sox http://bit.ly/software-small package. You can replace it by any other command-line-driven sound player.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 4 '11 at 23:00









        Gilles

        514k12110211550




        514k12110211550











        • Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
          – Mikel
          Mar 4 '11 at 23:20







        • 1




          time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
          – Martin Thoma
          Mar 5 '11 at 20:46

















        • Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
          – Mikel
          Mar 4 '11 at 23:20







        • 1




          time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
          – Martin Thoma
          Mar 5 '11 at 20:46
















        Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
        – Mikel
        Mar 4 '11 at 23:20





        Yep, play, aplay, or paplay. (My Ubuntu system has aplay and paplay by default.)
        – Mikel
        Mar 4 '11 at 23:20





        1




        1




        time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
        – Martin Thoma
        Mar 5 '11 at 20:46





        time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg worked, thanks.
        – Martin Thoma
        Mar 5 '11 at 20:46











        up vote
        8
        down vote













        spd-say



        sleep 2; spd-say 'get back to work'


        Infinite loop with -w if you need extra motivation:



        sleep 2; while true; do spd-say -w 'get back to work'; done


        Pre-installed on 14.04 via package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?



        Also add a popup



        This combo is a life saver:



        b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )


        and then:



        super-slow-command;b


        If I'm somewhere in the room, I'll hear it and know that the long job is done.



        Otherwise, I'll see the popup when I get back to my computer.



        Related: https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux






        share|improve this answer






















        • To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
          – dfarrell07
          Dec 13 '16 at 18:27















        up vote
        8
        down vote













        spd-say



        sleep 2; spd-say 'get back to work'


        Infinite loop with -w if you need extra motivation:



        sleep 2; while true; do spd-say -w 'get back to work'; done


        Pre-installed on 14.04 via package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?



        Also add a popup



        This combo is a life saver:



        b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )


        and then:



        super-slow-command;b


        If I'm somewhere in the room, I'll hear it and know that the long job is done.



        Otherwise, I'll see the popup when I get back to my computer.



        Related: https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux






        share|improve this answer






















        • To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
          – dfarrell07
          Dec 13 '16 at 18:27













        up vote
        8
        down vote










        up vote
        8
        down vote









        spd-say



        sleep 2; spd-say 'get back to work'


        Infinite loop with -w if you need extra motivation:



        sleep 2; while true; do spd-say -w 'get back to work'; done


        Pre-installed on 14.04 via package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?



        Also add a popup



        This combo is a life saver:



        b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )


        and then:



        super-slow-command;b


        If I'm somewhere in the room, I'll hear it and know that the long job is done.



        Otherwise, I'll see the popup when I get back to my computer.



        Related: https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux






        share|improve this answer














        spd-say



        sleep 2; spd-say 'get back to work'


        Infinite loop with -w if you need extra motivation:



        sleep 2; while true; do spd-say -w 'get back to work'; done


        Pre-installed on 14.04 via package speech-dispatcher: http://releases.ubuntu.com/trusty/ubuntu-14.04.4-desktop-amd64.manifest for blind people I suppose?



        Also add a popup



        This combo is a life saver:



        b() ( spd-say 'done'; zenity --info --text "$(date);$(pwd)" & )


        and then:



        super-slow-command;b


        If I'm somewhere in the room, I'll hear it and know that the long job is done.



        Otherwise, I'll see the popup when I get back to my computer.



        Related: https://stackoverflow.com/questions/7035/how-to-show-a-gui-message-box-from-a-bash-script-in-linux







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 13 at 9:29

























        answered Jul 28 '16 at 11:55









        Ciro Santilli 新疆改造中心 六四事件 法轮功

        4,46123938




        4,46123938











        • To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
          – dfarrell07
          Dec 13 '16 at 18:27

















        • To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
          – dfarrell07
          Dec 13 '16 at 18:27
















        To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
        – dfarrell07
        Dec 13 '16 at 18:27





        To get the spd-say tool associated with speech-dispatcher, you may need to install a subpackage like speech-dispatcher-utils (Fedora 24).
        – dfarrell07
        Dec 13 '16 at 18:27











        up vote
        3
        down vote













        You can also make this happen automatically.



        I will show you how in zsh, then add info about bash.



        The essence looks like this:



        preexec()

        starttime=$SECONDS


        precmd()

        if ((SECONDS - starttime >= 5)); then
        aplay "sound.wav"
        # or printf "b", or notify-send, or whatever
        fi



        You can also make it only do it if the program was Python, e.g.



        preexec()

        starttime=$SECONDS
        case $3 in python*)
        command_is_python=true;;
        *)
        command_is_python=false;;
        esac


        precmd()

        if $command_is_python && ((SECONDS - starttime >= 5)); then
        aplay "sound.wav"
        # or printf "b", or notify-send, or whatever
        fi



        In bash, the best way is to download preexec.bash.txt and source it (e.g. . ~/preexec.bash.txt at the top of your ~/.bashrc, then the above (or something close to it) should work. (Not sure about the $3 bit to check if the command is Python.)



        If you're using GNOME Terminal, I would also point you to Flashing GNOME Terminal. It's a patch I wrote that makes the terminal blink when a command is done, so you can Alt-Tab to something else, then it lets you know when it's done.






        share|improve this answer


























          up vote
          3
          down vote













          You can also make this happen automatically.



          I will show you how in zsh, then add info about bash.



          The essence looks like this:



          preexec()

          starttime=$SECONDS


          precmd()

          if ((SECONDS - starttime >= 5)); then
          aplay "sound.wav"
          # or printf "b", or notify-send, or whatever
          fi



          You can also make it only do it if the program was Python, e.g.



          preexec()

          starttime=$SECONDS
          case $3 in python*)
          command_is_python=true;;
          *)
          command_is_python=false;;
          esac


          precmd()

          if $command_is_python && ((SECONDS - starttime >= 5)); then
          aplay "sound.wav"
          # or printf "b", or notify-send, or whatever
          fi



          In bash, the best way is to download preexec.bash.txt and source it (e.g. . ~/preexec.bash.txt at the top of your ~/.bashrc, then the above (or something close to it) should work. (Not sure about the $3 bit to check if the command is Python.)



          If you're using GNOME Terminal, I would also point you to Flashing GNOME Terminal. It's a patch I wrote that makes the terminal blink when a command is done, so you can Alt-Tab to something else, then it lets you know when it's done.






          share|improve this answer
























            up vote
            3
            down vote










            up vote
            3
            down vote









            You can also make this happen automatically.



            I will show you how in zsh, then add info about bash.



            The essence looks like this:



            preexec()

            starttime=$SECONDS


            precmd()

            if ((SECONDS - starttime >= 5)); then
            aplay "sound.wav"
            # or printf "b", or notify-send, or whatever
            fi



            You can also make it only do it if the program was Python, e.g.



            preexec()

            starttime=$SECONDS
            case $3 in python*)
            command_is_python=true;;
            *)
            command_is_python=false;;
            esac


            precmd()

            if $command_is_python && ((SECONDS - starttime >= 5)); then
            aplay "sound.wav"
            # or printf "b", or notify-send, or whatever
            fi



            In bash, the best way is to download preexec.bash.txt and source it (e.g. . ~/preexec.bash.txt at the top of your ~/.bashrc, then the above (or something close to it) should work. (Not sure about the $3 bit to check if the command is Python.)



            If you're using GNOME Terminal, I would also point you to Flashing GNOME Terminal. It's a patch I wrote that makes the terminal blink when a command is done, so you can Alt-Tab to something else, then it lets you know when it's done.






            share|improve this answer














            You can also make this happen automatically.



            I will show you how in zsh, then add info about bash.



            The essence looks like this:



            preexec()

            starttime=$SECONDS


            precmd()

            if ((SECONDS - starttime >= 5)); then
            aplay "sound.wav"
            # or printf "b", or notify-send, or whatever
            fi



            You can also make it only do it if the program was Python, e.g.



            preexec()

            starttime=$SECONDS
            case $3 in python*)
            command_is_python=true;;
            *)
            command_is_python=false;;
            esac


            precmd()

            if $command_is_python && ((SECONDS - starttime >= 5)); then
            aplay "sound.wav"
            # or printf "b", or notify-send, or whatever
            fi



            In bash, the best way is to download preexec.bash.txt and source it (e.g. . ~/preexec.bash.txt at the top of your ~/.bashrc, then the above (or something close to it) should work. (Not sure about the $3 bit to check if the command is Python.)



            If you're using GNOME Terminal, I would also point you to Flashing GNOME Terminal. It's a patch I wrote that makes the terminal blink when a command is done, so you can Alt-Tab to something else, then it lets you know when it's done.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 4 '11 at 23:17

























            answered Mar 4 '11 at 23:12









            Mikel

            38.1k997123




            38.1k997123




















                up vote
                0
                down vote













                Personally, I use my-script && notify-send "done". This sends a desktop notification, which on Linux Mint looks like this:



                enter image description here





                share








                New contributor




                Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  up vote
                  0
                  down vote













                  Personally, I use my-script && notify-send "done". This sends a desktop notification, which on Linux Mint looks like this:



                  enter image description here





                  share








                  New contributor




                  Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.



















                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Personally, I use my-script && notify-send "done". This sends a desktop notification, which on Linux Mint looks like this:



                    enter image description here





                    share








                    New contributor




                    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    Personally, I use my-script && notify-send "done". This sends a desktop notification, which on Linux Mint looks like this:



                    enter image description here






                    share








                    New contributor




                    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.








                    share


                    share






                    New contributor




                    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.









                    answered 8 mins ago









                    Cee

                    1




                    1




                    New contributor




                    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.





                    New contributor





                    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.






                    Cee is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                    Check out our Code of Conduct.




















                        up vote
                        -1
                        down vote













                        Any player can be used. I'm adding cvlc for completeness.






                        share|improve this answer
























                          up vote
                          -1
                          down vote













                          Any player can be used. I'm adding cvlc for completeness.






                          share|improve this answer






















                            up vote
                            -1
                            down vote










                            up vote
                            -1
                            down vote









                            Any player can be used. I'm adding cvlc for completeness.






                            share|improve this answer












                            Any player can be used. I'm adding cvlc for completeness.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 26 '14 at 7:52









                            nponeccop

                            1668




                            1668



























                                 

                                draft saved


                                draft discarded















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f8607%2fhow-can-i-play-a-sound-when-script-execution-is-ready%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay