How can I play a sound when connected to the internet? I found a python script but there should be an simpler solution.
I just want to play a sound upon connection. Even notify-send would work.
I want to know when an internet connection is possible, so I do not start my browser and get a "can not find the webpage.".
I think I would do something like this:
The script will check for a "good connection" 5 times, waiting 5 seconds between each check, before giving up.
The definition of "good connection" here is: if we're able to send an ICMP request to google.com and receive an ICMP response 3 times, waiting 0.5 seconds between each request / response and completing the whole cycle within 3 seconds, then we have a "good connection".
If the script detects a "good connection", it will play
path/to/beep.wav
.You could put the script in
~/bin/connection_test.sh
, runchmod +x ~/bin/connection_test.sh
and add it to Startup Applications so that it executes upon logging in to the graphical session./path/to/beep.wav
must be the full path to the .wav sound to play (to test this I downloaded an mp3 file from https://pixabay.com/it/sound-effects/search/beeps/ and converted it to .wav usingffmpeg -i beep.mp3 beep.wav
).There are also ways to have your PC speaker beep instead, if you happen to have one these days and age.