terminal-notifier-guard 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +46 -0
- data/bin/terminal-notifier-failed +9 -0
- data/bin/terminal-notifier-notify +9 -0
- data/bin/terminal-notifier-pending +9 -0
- data/bin/terminal-notifier-success +9 -0
- data/lib/terminal-notifier-guard.rb +127 -0
- data/lib/terminal_notifier/guard/failed.rb +7 -0
- data/lib/terminal_notifier/guard/notify.rb +7 -0
- data/lib/terminal_notifier/guard/pending.rb +7 -0
- data/lib/terminal_notifier/guard/success.rb +7 -0
- metadata +131 -0
data/README.markdown
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# TerminalNotifier
|
2
|
+
|
3
|
+
A simple Ruby wrapper around the [`terminal-notifier`][HOMEPAGE] command-line
|
4
|
+
tool, which allows you to send User Notifications to the Notification Center on
|
5
|
+
Mac OS X 10.8, or higher.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
```
|
11
|
+
$ gem install terminal-notifier
|
12
|
+
```
|
13
|
+
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
For full information on all the options, see the tool’s [README][README].
|
18
|
+
|
19
|
+
Examples are:
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
TerminalNotifier.notify('Hello World')
|
23
|
+
TerminalNotifier.notify('Hello World', :title => 'Ruby', :subtitle => 'Programming Language')
|
24
|
+
TerminalNotifier.notify('Hello World', :activate => 'com.apple.Safari')
|
25
|
+
TerminalNotifier.notify('Hello World', :open => 'http://twitter.com/alloy')
|
26
|
+
TerminalNotifier.notify('Hello World', :execute => 'say "OMG"')
|
27
|
+
TerminalNotifier.notify('Hello World', :group => Process.pid)
|
28
|
+
|
29
|
+
TerminalNotifier.remove(Process.pid)
|
30
|
+
|
31
|
+
TerminalNotifier.list(Process.pid)
|
32
|
+
TerminalNotifier.list
|
33
|
+
```
|
34
|
+
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
All the works are available under the MIT license. **Except** for
|
39
|
+
‘Terminal.icns’, which is a copy of Apple’s Terminal.app icon and as such is
|
40
|
+
copyright of Apple.
|
41
|
+
|
42
|
+
See [LICENSE][LICENSE] for details.
|
43
|
+
|
44
|
+
[HOMEPAGE]: https://github.com/alloy/terminal-notifier
|
45
|
+
[README]: https://github.com/alloy/terminal-notifier/blob/master/README.markdown
|
46
|
+
[LICENSE]: https://github.com/alloy/terminal-notifier/blob/master/Ruby/LICENSE
|
@@ -0,0 +1,127 @@
|
|
1
|
+
%w(failed notify pending success).each do |type|
|
2
|
+
require File.expand_path("../terminal_notifier/guard/#{type}", __FILE__)
|
3
|
+
end
|
4
|
+
|
5
|
+
module TerminalNotifier
|
6
|
+
module Guard
|
7
|
+
include TerminalNotifier::Guard::Notify
|
8
|
+
include TerminalNotifier::Guard::Success
|
9
|
+
include TerminalNotifier::Guard::Failed
|
10
|
+
include TerminalNotifier::Guard::Pending
|
11
|
+
|
12
|
+
# Returns wether or not the current platform is Mac OS X 10.8, or higher.
|
13
|
+
def self.available?
|
14
|
+
if @available.nil?
|
15
|
+
@available = `uname`.strip == 'Darwin' && `sw_vers -productVersion`.strip >= '10.8'
|
16
|
+
end
|
17
|
+
@available
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.execute(verbose, options)
|
21
|
+
if available?
|
22
|
+
case options[:type]
|
23
|
+
when :failed
|
24
|
+
bin_path = TerminalNotifier::Guard::Failed::BIN_PATH
|
25
|
+
when :success
|
26
|
+
bin_path = TerminalNotifier::Guard::Success::BIN_PATH
|
27
|
+
when :pending
|
28
|
+
bin_path = TerminalNotifier::Guard::Pending::BIN_PATH
|
29
|
+
else
|
30
|
+
bin_path = TerminalNotifier::Guard::Notify::BIN_PATH
|
31
|
+
end
|
32
|
+
options.delete(:type) if options[:type]
|
33
|
+
|
34
|
+
command = [bin_path, *options.map { |k,v| ["-#{k}", v.to_s] }.flatten]
|
35
|
+
if RUBY_VERSION < '1.9'
|
36
|
+
require 'shellwords'
|
37
|
+
command = Shellwords.shelljoin(command)
|
38
|
+
end
|
39
|
+
result = ''
|
40
|
+
IO.popen(command) do |stdout|
|
41
|
+
output = stdout.read
|
42
|
+
STDOUT.print output if verbose
|
43
|
+
result << output
|
44
|
+
end
|
45
|
+
result
|
46
|
+
else
|
47
|
+
raise "terminal-notifier is only supported on Mac OS X 10.8, or higher."
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Sends a User Notification and returns wether or not it was a success.
|
52
|
+
#
|
53
|
+
# The available options are `:title`, `:group`, `:activate`, `:open`, and
|
54
|
+
# `:execute`. For a description of each option see:
|
55
|
+
#
|
56
|
+
# https://github.com/alloy/terminal-notifier/blob/master/README.markdown
|
57
|
+
#
|
58
|
+
# Examples are:
|
59
|
+
#
|
60
|
+
# TerminalNotifier.notify('Hello World')
|
61
|
+
# TerminalNotifier.notify('Hello World', :title => 'Ruby')
|
62
|
+
# TerminalNotifier.notify('Hello World', :group => Process.pid)
|
63
|
+
# TerminalNotifier.notify('Hello World', :activate => 'com.apple.Safari')
|
64
|
+
# TerminalNotifier.notify('Hello World', :open => 'http://twitter.com/alloy')
|
65
|
+
# TerminalNotifier.notify('Hello World', :execute => 'say "OMG"')
|
66
|
+
#
|
67
|
+
# Raises if not supported on the current platform.
|
68
|
+
def notify(message, options = {}, verbose = false)
|
69
|
+
TerminalNotifier::Guard.execute(verbose, options.merge(:message => message))
|
70
|
+
$?.success?
|
71
|
+
end
|
72
|
+
module_function :notify
|
73
|
+
|
74
|
+
def failed(message, options = {}, verbose = false)
|
75
|
+
TerminalNotifier::Guard.execute(verbose, options.merge(:message => message, :type => :failed))
|
76
|
+
$?.success?
|
77
|
+
end
|
78
|
+
module_function :failed
|
79
|
+
|
80
|
+
def pending(message, options = {}, verbose = false)
|
81
|
+
TerminalNotifier::Guard.execute(verbose, options.merge(:message => message, :type => :pending))
|
82
|
+
$?.success?
|
83
|
+
end
|
84
|
+
module_function :pending
|
85
|
+
|
86
|
+
def success(message, options = {}, verbose = false)
|
87
|
+
TerminalNotifier::Guard.execute(verbose, options.merge(:message => message, :type => :success))
|
88
|
+
$?.success?
|
89
|
+
end
|
90
|
+
module_function :success
|
91
|
+
|
92
|
+
# Removes a notification that was previously sent with the specified
|
93
|
+
# ‘group’ ID, if one exists.
|
94
|
+
#
|
95
|
+
# If no ‘group’ ID is given, all notifications are removed.
|
96
|
+
def remove(group = 'ALL', verbose = false)
|
97
|
+
TerminalNotifier::Guard.execute(verbose, :remove => group)
|
98
|
+
$?.success?
|
99
|
+
end
|
100
|
+
module_function :remove
|
101
|
+
|
102
|
+
LIST_FIELDS = [:group, :title, :subtitle, :message, :delivered_at].freeze
|
103
|
+
|
104
|
+
# If a ‘group’ ID is given, and a notification for that group exists,
|
105
|
+
# returns a hash with details about the notification.
|
106
|
+
#
|
107
|
+
# If no ‘group’ ID is given, an array of hashes describing all
|
108
|
+
# notifications.
|
109
|
+
#
|
110
|
+
# If no information is available this will return `nil`.
|
111
|
+
def list(group = 'ALL', verbose = false)
|
112
|
+
output = TerminalNotifier::Guard.execute(verbose, :list => group)
|
113
|
+
return if output.strip.empty?
|
114
|
+
|
115
|
+
require 'time'
|
116
|
+
notifications = output.split("\n")[1..-1].map do |line|
|
117
|
+
LIST_FIELDS.zip(line.split("\t")).inject({}) do |hash, (key, value)|
|
118
|
+
hash[key] = key == :delivered_at ? Time.parse(value) : (value unless value == '(null)')
|
119
|
+
hash
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
group == 'ALL' ? notifications : notifications.first
|
124
|
+
end
|
125
|
+
module_function :list
|
126
|
+
end
|
127
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: terminal-notifier-guard
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.4.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eloy Duran
|
9
|
+
- Wouter de Vos
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-08-14 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rake
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ! '>='
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: '0'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
name: bacon
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
type: :development
|
40
|
+
prerelease: false
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: mocha
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :development
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: mocha-on-bacon
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ! '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ! '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
description:
|
80
|
+
email:
|
81
|
+
- wouter.de.vos@springest.com
|
82
|
+
executables:
|
83
|
+
- terminal-notifier-notify
|
84
|
+
- terminal-notifier-success
|
85
|
+
- terminal-notifier-failed
|
86
|
+
- terminal-notifier-pending
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files:
|
89
|
+
- README.markdown
|
90
|
+
files:
|
91
|
+
- lib/terminal-notifier-guard.rb
|
92
|
+
- lib/terminal_notifier/guard/failed.rb
|
93
|
+
- lib/terminal_notifier/guard/notify.rb
|
94
|
+
- lib/terminal_notifier/guard/pending.rb
|
95
|
+
- lib/terminal_notifier/guard/success.rb
|
96
|
+
- bin/terminal-notifier-failed
|
97
|
+
- bin/terminal-notifier-notify
|
98
|
+
- bin/terminal-notifier-pending
|
99
|
+
- bin/terminal-notifier-success
|
100
|
+
- README.markdown
|
101
|
+
homepage: https://github.com/foxycoder/terminal-notifier
|
102
|
+
licenses: []
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ! '>='
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
hash: -2038140021858145580
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ! '>='
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
hash: -2038140021858145580
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 1.8.24
|
128
|
+
signing_key:
|
129
|
+
specification_version: 3
|
130
|
+
summary: Send User Notifications on Mac OS X 10.8 - with status icons.
|
131
|
+
test_files: []
|