Friday, 3 November 2017

playing music on hold when launching a bash command

 This works using MacOS afplay
!/bin/bash

moh_file=~/Downloads/moh.mp3

afplay $moh_file &
pid=$!
trap "kill $pid" 2

while read line; do echo -e $line; done


kill $pid


Usage:
$ long-running-command [args] | moh_player

If you want to retain colours, run it through script:
$ script -q /dev/null long-running-command [args] | moh_player