Skip to content

Instantly share code, notes, and snippets.

@peterhellberg
Created July 30, 2012 20:29
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 peterhellberg/3209893 to your computer and use it in GitHub Desktop.
Save peterhellberg/3209893 to your computer and use it in GitHub Desktop.
CLI for the terminal-notifier gem
#!/usr/bin/env ruby
require 'optparse'
require 'terminal-notifier'
options = {}
begin
parser = OptionParser.new do |opts|
opts.banner = "Usage: terminal-notifier MESSAGE [options]"
opts.on('-t', '--title TITLE') { |t| options[:title] = t }
opts.on('-g', '--group GROUP') { |g| options[:group] = g }
opts.on('-a', '--activate ACTIVATE') { |a| options[:activate] = a }
opts.on('-o', '--open OPEN') { |o| options[:open] = o }
opts.on('-e', '--execute EXECUTE') { |e| options[:execute] = e }
opts.on('-r', '--remove REMOVE') { |r| options[:remove] = r }
opts.on('-h', '--help') { puts opts; exit }
end
parser.parse!
rescue OptionParser::InvalidOption, OptionParser::InvalidArgument
puts $!.to_s
exit
end
if ARGV.any?
TerminalNotifier.notify(ARGV.first, options)
elsif options.has_key?(:remove)
TerminalNotifier.verbose_remove(options[:remove])
else
puts parser
end
@peterhellberg
Copy link
Author

Examples of usage

Activate Spotify

terminal-notifier 'New music!' -t Spotify -a 'com.Spotify.client' 

Open a website

terminal-notifier 'Tiny API with Nginx' -t c7.se -o 'http://c7.se/tiny-api-with-nginx/'

@peterhellberg
Copy link
Author

Version 1.3.0 of the terminal-notifier gem was just released and it has a built in command line interface, so you should probably use that instead :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment