Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get shell/ruby to make a noise (make my computer beep or play a sound/track) when my script breaks?

I'm running a testing script that runs over a website over and over again that runs hundreds of times over the course of several hours. I would like for ruby to starting playing a loud song/mp3 for example, to alert me while I'm in a different part of my fairly small apartment.

like image 938
boulder_ruby Avatar asked Oct 13 '12 22:10

boulder_ruby


1 Answers

I've found THE solution for all Mac OSX users. Credits to this blog post: http://www.mitchchn.me/2014/os-x-terminal/ for showing it to me:

Mac terminals have a command called say. say functions exactly like one might hope:

say "I'm done master"

does just that from the terminal.

Inside of a ruby script (in my case) this is easy to implement.

`say "I'm done master"`

works like a charm.

OK, I'd rather it be a female voice by default, but this is great.

To switch the voice go to System Preferences > Dictation and Speech > Text to Speech > System Voice

Vicki is probably the best sounding female voice

edit: oh yes, I wanted the computer to make a noise when it crashed. To do that in ruby:

def go(x)
  begin# starts rescue block
    puts "5/#{x} = #{5/x}"
  rescue
    `say "something is wrong, master."`
  end
end

go(0)
#=> ...
like image 132
boulder_ruby Avatar answered Oct 03 '22 14:10

boulder_ruby