๐Ÿ“ฆ deluan / macdeluan

๐Ÿ“„ growlnotify.rb ยท 110 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110#!/usr/bin/env ruby
# encoding: utf-8
# == Synopsis
#   Requires the terminal-notifier gem ([sudo] gem install terminal-notifier)

#   growlnotify wrapper to turn Growl alerts into Mountain Lion notifications
# Uses growlnotify option syntax to keep your old scripts working with the new shiny.
#
#   If you use Growl via growlnotify in your shell scripting, this script
# will replace Growl's alerts with Mountain Lion notifications.
# Name this script `growlnotify`, make it executable and replace
# `/usr/local/bin/growlnotify` (your location may vary) with it
# Now you shouldn't have to update any of your existing tools.
#
# == Examples
#   Send a Mountain Lion notification with title and message
#     growlnotify -m "message" -t "title"
#
# == Usage
#   growlnotify -m "search string" [-[tn] "title"]
#
#   For help use: growlnotify -h
#
# == Options
#     -m, --message MESSAGE            Copy just the url, defaults to full HTML tag
#     -t, --title TITLE                Title
#     -h, --help                       Display this screen
#     -v, --version                    Display version info
#     -n, --name NAME                  Pseudonym for --title
#     -s, --sticky                     Disabled in grownlnotify-notifier
#         --appIcon APPICON            Disabled in grownlnotify-notifier
#     -i, --icon ICON                  Disabled in grownlnotify-notifier
#     -I, --iconpath ICONPATH          Disabled in grownlnotify-notifier
#         --image IMAGEFILE            Disabled in grownlnotify-notifier
#     -p, --priority PRIO              Disabled in grownlnotify-notifier
#     -d, --indentifier ID             Disabled in grownlnotify-notifier
#     -H, --host HOSTNAME              Disabled in grownlnotify-notifier
#     -P, --password PASSWORD          Disabled in grownlnotify-notifier
#     -u, --udp                        Disabled in grownlnotify-notifier
#         --port PORTNUM               Disabled in grownlnotify-notifier
#     -a, --auth DIGEST                Disabled in grownlnotify-notifier
#     -c, --crypt                      Disabled in grownlnotify-notifier
#     -w, --wait                       Disabled in grownlnotify-notifier
#         --progress VALUE             Disabled in grownlnotify-notifier
#
# == Author
#   Brett Terpstra
#
# == Copyright
#   Public Domain
#
# == Web site
#   https://gist.github.com/ttscoff/3225914
#

MAJOR_VERSION = 1.0

require 'optparse'
require 'rubygems'
require 'terminal-notifier'

options = {}
optparse = OptionParser.new do|opts|
  opts.banner = "Usage: growlnotify -m \"message\" -t \"title\""
  options[:message] = false
  opts.on( '-m', '--message MESSAGE', 'Copy just the url, defaults to full HTML tag' ) do|message|
    options[:message] = message
  end
  options[:title] = false
  opts.on( '-t', '--title TITLE', 'Title' ) do |title|
   options[:title] = title
  end
  opts.on( '-h', '--help', 'Display this screen' ) do
    puts opts
    exit
  end
  opts.on('-v','--version','Display version info') do
    puts MAJOR_VERSION
    exit
  end
  opts.on('-n','--name NAME','Pseudonym for --title') do |name|
    options[:title] = name unless options[:title]
  end
  opts.on('-s','--sticky','Disabled in grownlnotify-notifier')
  opts.on('-a','--appIcon APPICON','Disabled in grownlnotify-notifier')
  opts.on('-i','--icon ICON','Disabled in grownlnotify-notifier')
  opts.on('-I','--iconpath ICONPATH','Disabled in grownlnotify-notifier')
  opts.on('--image IMAGEFILE','Disabled in grownlnotify-notifier')
  opts.on('-p', '--priority PRIO','Disabled in grownlnotify-notifier')
  opts.on('-d', '--indentifier ID','Disabled in grownlnotify-notifier')
  opts.on('-H', '--host HOSTNAME','Disabled in grownlnotify-notifier')
  opts.on('-P', '--password PASSWORD','Disabled in grownlnotify-notifier')
  opts.on('-u', '--udp','Disabled in grownlnotify-notifier')
  opts.on('--port PORTNUM','Disabled in grownlnotify-notifier')
  opts.on('-a','--auth DIGEST','Disabled in grownlnotify-notifier')
  opts.on('-c','--crypt','Disabled in grownlnotify-notifier')
  opts.on('-w','--wait','Disabled in grownlnotify-notifier')
  opts.on('--progress VALUE','Disabled in grownlnotify-notifier')
end

optparse.parse!

unless options[:message]
  puts "Message required."
  exit
end

options[:title] = "Terminal" unless options[:title]

TerminalNotifier.notify(options[:message], :title => options[:title])