0

I think my life would be that much better if a subtle sound effect was played when a task completed in a terminal window/tab that's not the current one. It'd be even better if an exit code 0 sounded different to any other exit code.

Is there any way to make this happen?

(I often start little scripts in a window, like uploading a file to a server, then switch to another tab to do something on the server. It'd be great to hear when the file has arrived.)

1 Answer 1

1

It's certainly achievable if you're using scripts, I often use

tput bel

at the point where work is complete. This will not only beep the terminal but put a badge on the dock icon as well.

In terms of handling exit codes then you can string a couple together for a different sound:

if command_or_exit_status
then
# exit OK
        tput bel
else
# not ok
        tput bel; tput bel;
fi
4
  • Ok, good to know, but I want this to work for all commands - not just certain scripts. Also, any sounds other than bel? Commented Feb 14, 2014 at 14:00
  • 1
    You could use afplay(1) to play any sound file. One way to handle arbitrary commands would be to adapt the above example to work as a wrapper with the command you want as an argument, i.e., test the exit status of $@ Commented Feb 14, 2014 at 14:15
  • Yeah, could be a good a workaround using a short alias. So I could end up with something like: ./mylongscript.sh ; zz where zz is an alias that checks the exit code then plays a sound appropriately. Commented Feb 14, 2014 at 14:53
  • Sure, or the other way around if you're grouping jobs up (or not) beepScript.sh command1 command2 ... Commented Feb 14, 2014 at 23:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .