Module: Notifier::TerminalNotifier

Extended by:
TerminalNotifier
Included in:
TerminalNotifier
Defined in:
lib/notifier/terminal_notifier.rb

Instance Method Summary collapse

Instance Method Details

#notify(options) ⇒ Object



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
# File 'lib/notifier/terminal_notifier.rb', line 11

def notify(options)
  command = [
    "terminal-notifier",
    "-group", "notifier-rubygems",
    "-title", options[:title].to_s,
    "-appIcon", options.fetch(:image, "").to_s,
    "-message", options[:message].to_s,
    "-subtitle", options.fetch(:subtitle, "").to_s
  ]

  # -sound with an empty string (e.g., "") will trigger the
  # default sound so we need to check for it.
  if options[:sound]
    command.concat([
      "-sound",
      options.fetch(:sound, "default").to_s
    ])
  end

  Thread.new do
    Open3.popen3(*command) do |_stdin, _stdout, _stderr|
      # noop
    end
  end.join
end

#supported?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/notifier/terminal_notifier.rb', line 7

def supported?
  Notifier.os?(/darwin/) && `which terminal-notifier` && $CHILD_STATUS == 0
end