#!/usr/bin/env ruby #scriptname: libs/rsstray.rb require 'gtk2' browser = 'libs/browser.sh' # signal is using for pushing commands to the main thread signal = Queue.new # Create tray icon si = Gtk::StatusIcon.new # Choose icon image si.icon_name = 'application-rss+xml' # Hide tray icon si.visible = false # Bind action mouse button si.signal_connect('activate') { signal.push('open') } # Bind menu mouse button si.signal_connect('popup-menu') { if signal.num_waiting != 0 then signal.push('') end } # Main thread that reads data from pipe Thread.start do # Get line line by line from pipe while line = STDIN.gets # A record isn't ready yet ready=0 # Parse line case line when /^Title: (.*)$/ then title = $1 when /^Link: (.*)$/ then link = $1 when /^Pub.date: (.*)$/ then pubdate = $1; ready=1 end # Read next line if record ins't ready if not (ready == 1) then next end # Send url to STDOUT puts link # Check if all properties are exist if defined? title and defined? link and defined? pubdate message = title + "\n\n" + link + "\n\n" + pubdate else message = "Something wrong has happened..." end # Set tooltip message for tray icon si.set_tooltip(message) # Make tray icon visible si.set_visible(true) # Wait for signal and open browser if signal is 'open' # and go futher if signal isn't 'open' while signal.pop == 'open' pid = fork { exec(browser, link ) } Process.detach(pid) end # Hide tray icon si.set_visible(false) end # Exit if EOF Gtk.main_quit end # Start main GTK loop Gtk.main
#!/bin/bash #scriptname: rssreader.sh # Go to script directory cd $(dirname $0) || exit 1 # Check arguments [ -z "$1" ] && { echo "usage: $0 http://address_of_rss_feed [number_of_initially_show_items]"; exit 0; } [ -z "$2" ] && num=1 || num=$2 # Lunch rsstail and tray icon rsstail -zpl -n $num -u "$1" | libs/rsstray.rb
#!/bin/bash #scriptname: libs/browser.sh firefox "$1" 2> /dev/null & disown
rssreader.sh http://habrahabr.ru/rss 5
Source: https://habr.com/ru/post/115536/
All Articles