Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play sound for notifications when they execute. #35

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ A simple Ruby wrapper around the [`terminal-notifier`](https://github.com/alloy/
tool, which allows you to send User Notifications to the Notification Center on
Mac OS X 10.8, or higher.

This version has 4 different icons included for each status that
This version has 4 different icons and sounds included for each status that
[Guard][GUARD] supports:

1. Failed
2. Notify
3. Pending
4. Success
1. Failed (Sound is Sosumi)
2. Notify (Sound is Blow)
3. Pending (Sound is Morse)
4. Success (Sound is Hero)


## Installation
Expand Down
10 changes: 9 additions & 1 deletion lib/terminal-notifier-guard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Guard
VERSION = "1.7.0"
ICONS_PATH = File.expand_path("../../icons", __FILE__)
GUARD_ICON = File.join(ICONS_PATH, 'Guard.icns')
OSX_BUILT_IN_SOUNDS = { :notify => 'Blow', :failed => 'Sosumi', :pending => 'Morse', :success => 'Hero' }.freeze

def self.osx_version
Gem::Version.new(`sw_vers -productVersion`.strip)
Expand Down Expand Up @@ -49,7 +50,8 @@ def self.bin_path

def self.execute(verbose, options)
if available? && installed?
options.merge!({ :contentImage=> GUARD_ICON, :appIcon => icon(options.delete(:type)) })
type = options.delete(:type)
options.merge!({ :contentImage=> GUARD_ICON, :appIcon => icon(type), :sound => sound(type) })

command = [bin_path, *options.map { |k,v| ["-#{k}", v.to_s] }.flatten]
if RUBY_VERSION < '1.9'
Expand Down Expand Up @@ -117,6 +119,12 @@ def icon(type = :notify)
end
module_function :icon

def sound(type = :notify)
type ||= :notify
OSX_BUILT_IN_SOUNDS[type.to_sym]
end
module_function :sound

# Removes a notification that was previously sent with the specified
# ‘group’ ID, if one exists.
#
Expand Down
18 changes: 9 additions & 9 deletions spec/terminal-notifier-guard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
describe "TerminalNotifier::Guard" do
describe ".execute" do
it "executes the tool with the given options" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon]
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon, '-sound', TerminalNotifier::Guard.sound]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -20,8 +20,8 @@
TerminalNotifier::Guard.execute(false, :message => 'ZOMG')
end

it "executes with the right icon path according to the type option" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:success)]
it "executes with the right icon path and sound according to the type option" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:success), '-sound', TerminalNotifier::Guard.sound(:success)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand Down Expand Up @@ -86,8 +86,8 @@
end

describe ".failed" do
it "executes with the 'failed' icon flag" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:failed)]
it "executes with the 'failed' icon flag and sound flag" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:failed), '-sound', TerminalNotifier::Guard.sound(:failed)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -98,8 +98,8 @@
end

describe ".success" do
it "executes with the 'success' icon flag" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:success)]
it "executes with the 'success' icon flag and sound flag" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:success), '-sound', TerminalNotifier::Guard.sound(:success)]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand All @@ -110,8 +110,8 @@
end

describe ".pending" do
it "executes with the 'pending' icon flag" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:pending)]
it "executes with the 'pending' icon flag and sound flag" do
command = [TerminalNotifier::Guard.bin_path, '-message', 'ZOMG', '-contentImage', TerminalNotifier::Guard::GUARD_ICON, '-appIcon', TerminalNotifier::Guard.icon(:pending), '-sound', TerminalNotifier::Guard.sound(:pending) ]
if RUBY_VERSION < '1.9'
require 'shellwords'
command = Shellwords.shelljoin(command)
Expand Down