Skip to content

Instantly share code, notes, and snippets.

@eddiefisher
Last active March 21, 2016 16:02
Show Gist options
  • Save eddiefisher/ada6e56e714090092e5d to your computer and use it in GitHub Desktop.
Save eddiefisher/ada6e56e714090092e5d to your computer and use it in GitHub Desktop.
mcabber eventcmd osx notification via ruby
#!/usr/bin/env ruby
require 'terminal-notifier'
event, arg1, arg2, filename = ARGV
history = "#{Dir.home}/.mcabber/histo"
filename = "#{history}/#{arg2}"
log = File.open "#{Dir.home}/.mcabber/eventcmd.log", 'a'
log.write "#{event}, #{arg1}, #{arg2}, #{filename}\n"
log.write "filename: #{filename}\n"
def notify(msg, arg2)
# TerminalNotifier.notify(msg, title: "Mcabber", subtitle: "#{arg2}", sound: 'default', activate: 'com.apple.Terminal') # terminal
TerminalNotifier.notify(msg, title: "Mcabber", subtitle: "#{arg2}", sound: 'default', activate: 'com.googlecode.iterm2') # iterm2
end
case event
when "MSG"
case arg1
when "IN"
if filename && File.exists?(filename)
file = File.open(filename).to_a
msg = file.last[26..-1]
else
msg = "file not found"
end
notify(msg, arg2)
when "OUT"
end
when "STATUS"
msg = {
"O" => "online",
"F" => "chat",
"A" => "away",
"N" => "xa",
"D" => "dnd",
"I" => "invisible",
"_" => "offline",
"?" => "error",
"X" => "requested"
}[arg1.to_s]
notify(msg, arg2)
when "UNREAD"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment