Skip to content

Instantly share code, notes, and snippets.

@mhink
Created November 21, 2016 19:37
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 mhink/5ae5e691cc2ad5a4cf84df1a88f82e18 to your computer and use it in GitHub Desktop.
Save mhink/5ae5e691cc2ad5a4cf84df1a88f82e18 to your computer and use it in GitHub Desktop.
A quick ruby script for OS X notifications from the shell (even in tmux!)
#! /usr/bin/env ruby
require 'optparse'
@reattach = true
@title = "Shell Notification"
OptionParser.new do |opts|
opts.banner = "Usage: notify [options] \"This is a notification\""
opts.on("--no-reattach", "don't use 'reattach-to-user-namespace") do |noreattach|
@reattach = false
end
opts.on("-ttitle", "--title=title", "set a title for the notification popup") do |title|
@title = title
end
opts.on("-h", "--help", "show this message") do
puts opts
exit
end
end.parse!
@message = ARGV[0]
unless defined? @message
STDERR.puts "No message given!"
exit 1
end
osacmd = "display notification \"#@message\" with title \"#@title\""
cmd = [
@reattach ? "reattach-to-user-namespace" : "",
"osascript -e",
"'#{osacmd}'"
]
system cmd.join(" ")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment