Created
July 30, 2012 20:29
-
-
Save peterhellberg/3209893 to your computer and use it in GitHub Desktop.
CLI for the terminal-notifier gem
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' | |
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 |
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
Examples of usage
Activate Spotify
Open a website