How can I play a sound when script execution is ready?
Solution 1
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.)
Solution 2
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
or if you prefer the carrot:
sleep 2; while true; do spd-say -t female1 -w "I'm done, come back to me, darling"; 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
stands for beep
):
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
Solution 3
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
Solution 4
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.
Solution 5
Personally, I use my-script && notify-send "done"
. This sends a desktop notification, which on Linux Mint(Cinnamon) looks like this:
Related videos on Youtube
Robert Strauch
I also have a blog about Code, the Web and Cyberculture and a career profile on Stackoverflow. My interests are mainly machine-learning, neural-networks, data-analysis.
Updated on September 17, 2022Comments
-
Robert Strauch almost 2 years
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).
-
Mikel over 13 yearsAre you using
bash
orzsh
? There are actually some ways of making this happen automatically, but they're quite involved and depend on which shell you are using. -
Robert Strauch over 13 years$ echo $SHELL returns "/bin/bash"
-
Gabriel Staples over 4 yearsSame question: askubuntu.com/questions/277215/…
-
-
Mikel over 13 years
notify-more
ornotify-send
could indeed be useful alternatives to playing a sound. -
Mikel over 13 years+1
paplay
is probably the best command to use to play a sound on a "modern" Linux system. -
Michael Mrozek over 13 years@Mikel I'm completely addicted to libnotify; everything on my system pops up notifications
-
Robert Strauch over 13 yearsprintf '\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
-
Robert Strauch over 13 years
time python MyScript.py -n 40; paplay /usr/share/sounds/ubuntu/stereo/desktop-login.ogg
worked, thanks. -
laggingreflex almost 10 years
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. -
musiphil over 9 years@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. -
user2469006 about 9 years
paplay
works well for me. You find a nice free notification sound from CyanogenMod, github.com/CyanogenMod/android_frameworks_base/tree/cm-12.0/…. I'm usingogg/Adara.ogg
which has a light percussive sound. -
cprn almost 9 years@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
-
dfarrell07 over 7 yearsTo get the
spd-say
tool associated withspeech-dispatcher
, you may need to install a subpackage likespeech-dispatcher-utils
(Fedora 24). -
Antonio over 2 yearsBrilliant! I used to use
beep
but it became so complicated to configure,spd-say
it's a super cool readily available alternative!