| 1 | #!/usr/bin/ruby |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | require "drb/drb" |
|---|
| 5 | require "optparse" |
|---|
| 6 | |
|---|
| 7 | host, port = 'localhost', '9955' |
|---|
| 8 | title = message = nil |
|---|
| 9 | icon = nil |
|---|
| 10 | sticky = false |
|---|
| 11 | type = 'notice' |
|---|
| 12 | |
|---|
| 13 | app_name, app_icon = "GrowlRemote", nil |
|---|
| 14 | types, default_types = ["notice"], nil |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | begin |
|---|
| 18 | eval(File.read("#{ENV['HOME']}/.growlclient")) |
|---|
| 19 | rescue Errno::ENOENT |
|---|
| 20 | end |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | OptionParser.new do |opts| |
|---|
| 24 | opts.separator "" |
|---|
| 25 | opts.separator "Required:" |
|---|
| 26 | opts.on('-t', '--title TITLE') {|v| title = v } |
|---|
| 27 | opts.on('-m', '--message MESSAGE') {|v| message = v } |
|---|
| 28 | |
|---|
| 29 | opts.separator "" |
|---|
| 30 | opts.separator "Optional:" |
|---|
| 31 | opts.on('-s', '--sticky') { sticky = true } |
|---|
| 32 | opts.on('-i', '--icon FILE (nil)') {|v| icon = File.read(v) } |
|---|
| 33 | opts.on('-h', '--host HOST (localhost)') {|v| host = v } |
|---|
| 34 | opts.on('-p', '--port PORT (9955)') {|v| port = v } |
|---|
| 35 | |
|---|
| 36 | opts.separator "" |
|---|
| 37 | opts.on('--appname NAME') {|v| app_name = v } |
|---|
| 38 | opts.on('--appicon FILE') {|v| app_icon = File.read(v) } |
|---|
| 39 | opts.on('--type TYPE') {|v| type = v } |
|---|
| 40 | opts.on('--types TYPES', '(comma-deliminated)') {|v| types = v.split(/,/) } |
|---|
| 41 | opts.on('--dtypes TYPES', '(comma-deliminated)') {|v| default_types = v.split(/,/) } |
|---|
| 42 | opts.parse!(ARGV) |
|---|
| 43 | |
|---|
| 44 | unless title && message |
|---|
| 45 | puts opts |
|---|
| 46 | exit |
|---|
| 47 | end |
|---|
| 48 | |
|---|
| 49 | unless default_types |
|---|
| 50 | default_types = types |
|---|
| 51 | end |
|---|
| 52 | end |
|---|
| 53 | |
|---|
| 54 | begin |
|---|
| 55 | n = DRbObject.new_with_uri("druby://#{host}:#{port}") |
|---|
| 56 | s = n.register(app_name, types, default_types, app_icon) |
|---|
| 57 | if s |
|---|
| 58 | s.notify(type, title, message, icon, icon, sticky) |
|---|
| 59 | else |
|---|
| 60 | n.notify(app_name, title, message, type, icon, sticky) |
|---|
| 61 | end |
|---|
| 62 | rescue Exception => e |
|---|
| 63 | if $DEBUG |
|---|
| 64 | puts e.message |
|---|
| 65 | puts e.backtrace |
|---|
| 66 | end |
|---|
| 67 | end |
|---|
| 68 | |
|---|