Skip to content

Instantly share code, notes, and snippets.

@DriftwoodJP
Created August 19, 2014 12:01
Show Gist options
  • Save DriftwoodJP/cacf349631831168439c to your computer and use it in GitHub Desktop.
Save DriftwoodJP/cacf349631831168439c to your computer and use it in GitHub Desktop.
Mac に数字を読み上げてもらうビンゴ抽選器をつくる | http://www.d-wood.com/blog/2014/08/22_6662.html
require 'readline'
def notification(message, title='Bingo Machine', subtitle='', sound='Glass')
[message, title, subtitle, sound].each{|arg| arg.gsub!(/"/, '\\\\\"')}
scpt = 'display notification "%s"' % message
scpt << ' with title "%s"' % title
scpt << ' subtitle "%s"' % subtitle unless subtitle.empty?
scpt << ' sound name "%s"' % sound unless sound.empty?
system %|osascript -e "#{scpt.gsub(/"/, '\"')}"|
sleep 0.5
system %|osascript -e "say #{message}"|
end
a = (1..75).to_a.shuffle
print('> Press enter to start!', "\n")
a.each { |num|
buf = Readline.readline('> ', true)
break if buf == 'q'
print('> ', num, "\n")
notification num.to_s
}
print("\n", '> Finish!', "\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment