Last active
August 29, 2015 13:59
-
-
Save zakuroishikuro/10987209 to your computer and use it in GitHub Desktop.
RubyからMacの通知センターに通知するメソッド (AppleScript経由)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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