A long time ago I watched a TV show, which was taking place in a South Korean shipyard. I cannot remember whether it was one of these mega-structure programmes or something similar, but I do remember when the huge cranes in the shipyard where moving they were playing tunes instead of alarms, like when trucks are driving in reverse or similar. I have thought a lot about the rationale behind this and has come to the conclusion, that it was important to create a distinct sound with would stand our from all of the other noise in the shipyard.
Today I work at a workstation with 3 screens, I have a plethora of different windows, editors, terminals, database interfaces, email client etc.
I am using headphones with noise cancellation since I am seated in an open office space and I want to guard my attention span. I listen to music, primarily electronica, without lyrics, since I have discovered that I am more easily distracted, if I listen to tunes with lyrics (If somebody can explain this phenomenon, I am all ears). Some recommendations for “Background Music for Coding” in addition to: musicforprograming.net, which I listen to regularly together with some cool playlists on Spotify).
When coding my eyes are occupied, with source code, script output, compiler/interpreter/toolchain feedback.
At the same time a have long a short processes, running in the front or in the background. These are often jobs, such as:
- Test runs
- Docker builds
- Test database builds
So when I discovered @tara-gibbs hey
utility (Gist: hey) I was thrilled and I put it to use, after some time I decided to extend my use of audible feedback.
#!/bin/bash #
REF: https://gist.github.com/tara-gibbs/cf91bc86c580f244de0ae9f5978edaac
/usr/bin/osascript -e "display notification \"$\*\" with title \"Hey!\""
/usr/bin/say -v Samantha "Hey! $\*"
# Setup: Add this to your /usr/local/bin in a file called hey. chmod +x it to make it an executable.
# Usage: sleep 2 && hey wake up!
This is my local version, including a reference to Tara’s original Gist. Please star Tara’s Gist if you use/like it.
Based on Tara’s script I decided to write a special script for Docker build, named: docker-build
(Gist: docker-build), sort of an equivalent of docker-compose
.
A disclaimer, these scripts are not implemented for distribution and need tweaking before being able to run on your machine and they are implemented on OSX. It should however be possible to dig up similar utilities on other operatings systems for emitting alerts, voice output and playing sound files, making the scripts work on other platforms.
#!/bin/bash
say -v Samantha "Docker build commencing...";
# Receives: messages and return value from Docker build
function emit() {
if [ $2 -eq 0 ]
then
# green output
echo -e "\033[92m$1";
else
# red output
echo -e "\033[91m$1";
fi
# Resetting colouring
echo -e "\033[0m";
hey $1;
}
./docker-build.sh
if [ $? -eq 0 ]
then
/usr/bin/afplay $HOME/Sounds/success.wav
emit "Docker build completed" 0
else
/usr/bin/afplay $HOME/Sounds/warning.wav
emit "Docker build failed" 1
exit 1
fi
exit 0
Do note that it uses both differentiated colorized output and sounds based on the success of the Docker build. All my Docker builds have a docker-build.sh
and docker-run.sh
(and docker-entrypoint.sh
) to avoid entering the same values over and over again for different projects and keeping the projects somewhat uniform – your shell history might not go as far back as your work log. An example using this approach can be found on GitHub.
On the forever fascinating Internet I fell over some sound loops from Science Fiction movies. Finding the “Nostromo Ambient Engine Noise” particularly stimulating I noticed it has some discrete beeps in the background, like something was indicating a pulse or something running and it reminded me of the cranes from the South Korean shipyard, where I have still not been able to dig up any snippets or examples.
Anyway I decided to see if I could incorporate the same sort of pulse in my long running scripts. This sort of solves the issue of me not catching the termination signal, I can hear that the pulse is no longer emitted.
The prototype consists of two scripts (please forgive my very basic Shell-scripting knowledge and style, it is not what I primarily code in, so suggestions for improvements are always welcome).
alive.sh
emits a sound every to seconds and runs forever.
#!/bin/bash
while [1]; do
/usr/bin/afplay $HOME/Sounds/alive.wav;
sleep 2;
done
exit 0
fork.sh
forks of alive-beep.sh
and does what ever is is supposed to do, when done it terminates (kill
) alive-beep.sh
and completes with emitting a sound indicating that it has finished, as for the docker-build script this could be changed into reflecting the outcome of the run, differentiating on sound and color.
#!/bin/bash
alive-beep.sh &
sleep 6;
kill $!
/usr/bin/afplay $HOME/Sounds/success.wav
exit 0
If we apply this to docker-build, it could look like the following:
#!/bin/bash
say -v Samantha "Docker build commencing...";
# Receives: messages and return value from Docker build
function emit() {
if [ $2 -eq 0 ]
then
# green output
echo -e "\033[92m$1";
else
# red output
echo -e "\033[91m$1";
fi
# Resetting colouring
echo -e "\033[0m";
hey $1;
}
alive-beep.sh &
./docker-build.sh
kill $!
if [ $? -eq 0 ]
then
/usr/bin/afplay $HOME/Sounds/success.wav
emit "Docker build completed" 0
else
/usr/bin/afplay $HOME/Sounds/warning.wav
emit "Docker build failed" 1
exit 1
fi
exit 0
(Gist: docker-build)
I am far from done with experimenting with audible output, I need to try out other sounds, differentiated volume and general integration with more of my scripts.
If this article has inspired you and you come up with something cool, let me know. If you find issues with the scripts, please let me know.
Top comments (0)