forked from Codaisseur/terminal-notifier-guard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
.DS_Store | ||
DerivedData | ||
xcuserdata | ||
Ruby/*.zip | ||
Ruby/*.gem | ||
Ruby/vendor |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
*.gem | ||
*.rbc | ||
.bundle | ||
.config | ||
.yardoc | ||
Gemfile.lock | ||
InstalledFiles | ||
_yardoc | ||
coverage | ||
doc/ | ||
lib/bundler/man | ||
pkg | ||
rdoc | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
tmp |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
All the works are available under the MIT license. **Except** for | ||
‘Terminal.icns’, which is a copy of Apple’s Terminal.app icon and as such is | ||
copyright of Apple. | ||
|
||
Copyright (C) 2012 Eloy Durán <eloy.de.enige@gmail.com> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# TerminalNotifier | ||
|
||
A simple Ruby wrapper around the [`terminal-notifier`][HOMEPAGE] command-line | ||
tool, which allows you to send User Notifications to the Notification Center on | ||
Mac OS X 10.8, or higher. | ||
|
||
|
||
## Installation | ||
|
||
``` | ||
$ gem install terminal-notifier | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
Examples are: | ||
|
||
```ruby | ||
TerminalNotifier.notify('Hello World') | ||
TerminalNotifier.notify('Hello World', :title => 'Ruby') | ||
TerminalNotifier.notify('Hello World', :group => Process.pid) | ||
TerminalNotifier.notify('Hello World', :activate => 'com.apple.Safari') | ||
TerminalNotifier.notify('Hello World', :open => 'http://twitter.com/alloy') | ||
TerminalNotifier.notify('Hello World', :execute => 'say "OMG"') | ||
``` | ||
|
||
|
||
## License | ||
|
||
All the works are available under the MIT license. **Except** for | ||
‘Terminal.icns’, which is a copy of Apple’s Terminal.app icon and as such is | ||
copyright of Apple. | ||
|
||
See [LICENSE][LICENSE] for details. | ||
|
||
[HOMEPAGE]: https://github.com/alloy/terminal-notifier | ||
[LICENSE]: https://github.com/alloy/terminal-notifier/blob/master/Ruby/LICENSE |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
def version | ||
@version ||= begin | ||
plist = File.expand_path('../../Terminal Notifier/Terminal Notifier-Info.plist', __FILE__) | ||
`/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' '#{plist}'`.strip | ||
end | ||
end | ||
|
||
def filename | ||
"terminal-notifier_#{version}" | ||
end | ||
|
||
def zipfile | ||
"#{filename}.zip" | ||
end | ||
|
||
task :clean do | ||
rm zipfile | ||
rm_rf "vendor" | ||
end | ||
|
||
task :update_build do | ||
unless File.exist?(zipfile) | ||
sh "curl -O 'http://cloud.github.com/downloads/alloy/terminal-notifier/terminal-notifier_#{version}.zip'" | ||
end | ||
|
||
rm_rf "vendor" | ||
mkdir "vendor" | ||
|
||
sh "unzip -o -d vendor #{zipfile}" | ||
mv "vendor/#{filename}", "vendor/terminal-notifier" | ||
end | ||
|
||
task :gem => :update_build do | ||
sh "gem build terminal-notifier.gemspec" | ||
end | ||
|
||
task :default => :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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module TerminalNotifier | ||
BIN_PATH = File.expand_path('../../vendor/terminal-notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier', __FILE__) | ||
|
||
# Returns wether or not the current platform is Mac OS X 10.8, or higher. | ||
def self.available? | ||
if @available.nil? | ||
@available = `uname`.strip == 'Darwin' && `sw_vers -productVersion`.strip >= '10.8' | ||
end | ||
@available | ||
end | ||
|
||
# Executes the `terminal-notifier` tool through Kernel::system while | ||
# redirecting output to `/dev/null`. | ||
def self.silent_execute(options) | ||
stdout = STDOUT.clone | ||
STDOUT.reopen(File.new('/dev/null', 'w')) | ||
system(BIN_PATH, *options) | ||
ensure | ||
STDOUT.reopen(stdout) | ||
end | ||
|
||
# Sends a User Notification and returns wether or not it was a success. | ||
# | ||
# The available options are `:title`, `:group`, `:activate`, `:open`, and | ||
# `:execute`. For a description of each option see: | ||
# | ||
# https://github.com/alloy/terminal-notifier/blob/master/README.markdown | ||
# | ||
# Examples are: | ||
# | ||
# TerminalNotifier.notify('Hello World') | ||
# TerminalNotifier.notify('Hello World', :title => 'Ruby') | ||
# TerminalNotifier.notify('Hello World', :group => Process.pid) | ||
# TerminalNotifier.notify('Hello World', :activate => 'com.apple.Safari') | ||
# TerminalNotifier.notify('Hello World', :open => 'http://twitter.com/alloy') | ||
# TerminalNotifier.notify('Hello World', :execute => 'say "OMG"') | ||
# | ||
# Raises if not supported on the current platform. | ||
def notify(message, options = {}) | ||
if TerminalNotifier.available? | ||
TerminalNotifier.silent_execute(options.merge(:message => message).map { |k,v| ["-#{k}", v.to_s] }.flatten) | ||
else | ||
raise "terminal-notifier is only supported on Mac OS X 10.8, or higher." | ||
end | ||
end | ||
module_function :notify | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# -*- encoding: utf-8 -*- | ||
plist = File.expand_path('../../Terminal Notifier/Terminal Notifier-Info.plist', __FILE__) | ||
version = `/usr/libexec/PlistBuddy -c 'Print :CFBundleShortVersionString' '#{plist}'`.strip | ||
|
||
Gem::Specification.new do |gem| | ||
gem.name = "terminal-notifier" | ||
gem.version = version | ||
gem.summary = 'Send User Notifications on Mac OS X 10.8.' | ||
gem.authors = ["Eloy Duran"] | ||
gem.email = ["eloy.de.enige@gmail.com"] | ||
gem.homepage = 'https://github.com/alloy/terminal-notifier' | ||
|
||
gem.files = ['lib/terminal-notifier.rb'] + Dir.glob('vendor/terminal-notifier/**/*') | ||
gem.require_paths = ['lib'] | ||
|
||
gem.extra_rdoc_files = ['README.markdown'] | ||
end |