From 4100928b4ac9f37c6ff596d67556f08a1bf68275 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Tue, 24 Sep 2013 10:14:22 -0700 Subject: [PATCH] add linky-notifier script --- linky-notify | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 linky-notify diff --git a/linky-notify b/linky-notify new file mode 100755 index 0000000..6b36b6c --- /dev/null +++ b/linky-notify @@ -0,0 +1,24 @@ +#!/usr/bin/env ruby + +require 'json' +require 'shellwords' + +def e(s) + Shellwords.escape(s) +end + +def main + dir = ENV['WATCH_DIR'] + created = JSON.parse(ENV['WATCH_CREATED']) + created.each do |filename| + path = File.join(dir, filename) + title, url, _ = File.readlines(path).map(&:strip) + output = `/Users/sjs/.rbenv/shims/terminal-notifier -title #{e(title)} -message #{e(url)} -open #{e(url)} 2>&1` + unless $?.success? + exit 1 + end + File.rename(path, File.join(dir, 'Archive', filename)) + end +end + +main if $0 == __FILE__