Created
November 21, 2016 19:37
-
-
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!)
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
#! /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