Skip to content

Instantly share code, notes, and snippets.

@zakuroishikuro
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zakuroishikuro/10987209 to your computer and use it in GitHub Desktop.
Save zakuroishikuro/10987209 to your computer and use it in GitHub Desktop.
RubyからMacの通知センターに通知するメソッド (AppleScript経由)
def notification(message, title:"Ruby", subtitle:"", sound:"")
[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(/"/, '\"')}"|
end
# single & double quatation sample
notification %q|"I thought what I'd do was, I'd pretend I was one of those deaf-mutes."|, sound:'Glass'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment