Snarl Network Protocol(SNP) Client for Snarl. You can send messages to Snarl on LAN.
Snarl is a popup-message application on Windows. Alike Growl. www.fullphat.net/ SNP 1.0 documentation is here. www.fullphat.net/dev/snp/index.htm
If you are able to read Japanese, please read doc-ja/README.rdoc.ja.
-
Ruby 1.8.6 or later (including 1.9.1)
gem install snarl-snp
No other gems are required.
ezookojo@gmail.com d.hatena.ne.jp/kitamomonga/ (in Japanese)
@host is a Windows machine host which is running Snarl (LAN only). Set the value in advance, then copy and paste codes on irb.
@host = '192.168.0.2' # Snarl machine host
When nil/undef, Snarl::SNP uses ‘127.0.0.1’. Default port is 9887.
0.2.0 feature. It maybe seems to be easy.
require 'rubygems' require 'snarl/snp' Snarl::SNP.load(<<YAML) host : #{@host} app : Ruby-Snarl title : popup title text : hello! timeout : 5 unregister : false YAML require 'rubygems' require 'snarl/snp' yaml = <<YAML host : #{@host} app : Ruby-Snarl class : - [class1, name1] - [class2, name2] YAML Snarl::SNP.load(yaml) do |snp| snp.notification(:title => 'title', :text => 'text', :class => 'class1') end require 'rubygems' require 'snarl/snp' Snarl::SNP.load(<<YAML) host : #{@host} app : Ruby-Snarl class : - [class1, name1] - [class2, name2] notification : title : title text : text class : class1 logfile : $stdout YAML require 'rubygems' require 'snarl/snp' Snarl::SNP.load(<<YAML) host : #{@host} app : Ruby-Snarl notification : - title : 1st post! text : message1 - title : 2nd post! text : message2 YAML
For YAML details, see YAML.rdoc.
require 'rubygems' require 'snarl/snp' Snarl::SNP.show_message(@host, 'title', 'Hello, Snarl!')
or
Snarl::SNP.new(@host).notification('title', 'Hello, Snarl!') Snarl::SNP.open(@host){|snp| snp.notification('title', 'Hello, Snarl!')}
Snarl::SNP can simply send message in this way, but you cannot change popup settings on Snarl. If you want to change popup settings(i.e. changing a color style), at least register an “application name”.
NOTE: The multibyte anonymous application messages may not work well.
require 'rubygems' require 'snarl/snp' Snarl::SNP.open(@host) do |snp| snp.register('Ruby-Snarl') snp.notification('title', 'text', nil, 10) end # if you wish # Snarl::SNP.new(@host).unregister('Ruby-Snarl')
“application name” is Ruby-Snarl. On Snarl, it’s shown in “Apps” - “The following applications are registered with Snarl:” - “Ruby-Snarl on xxx.xxx.xxx.xxx”. You can change popup settings now. If you want to classify messages(i.e. a green popup message, a red popup message, …), set classes.
When sending “unregister” or starting Snarl, application names are hideen from setting window.
require 'rubygems' require 'snarl/snp' Snarl::SNP.open(@host) do |snp| snp.unregister('Ruby-Snarl') end
An unregister command makes the application “inactive”. The application is removed from Snarl setting window, and Snarl users can not change their popup settings. If you wish to allow users to change the popup settings, you should not use unregister commands on your usual scripts.
require 'rubygems' require 'snarl/snp' Snarl::SNP.open(@host) do |snp| snp.register('Ruby-Snarl') snp.add_class('type1') snp.add_class('type2') snp.notification('title', 'type1 text', nil, 10, 'type1') snp.notification('title', 'type2 text', nil, 10, 'type2') end # if you wish # Snarl::SNP.new(@host).unregister('Ruby-Snarl')
Classes are used for message classification. They are shown in “Apps” - “Notification classes:”. If you change style of “type1” class on Snarl, all “type1” messages of application “Ruby-Snarl” pop in your way.
require 'rubygems' require 'snarl/snp' Snarl::SNP.open(@host) do |snp| snp.request("type=SNP#?version=1.1#?action=register#?app=Ruby-Snarl\r\n") snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type1\r\n") snp.request("type=SNP#?version=1.1#?action=add_class#?app=Ruby-Snarl#?class=type2\r\n") snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type1#?title=title#?text=type1 text!#?timeout=10\r\n") snp.request("type=SNP#?version=1.1#?action=notification#?app=Ruby-Snarl#?class=type2#?title=title#?text=type2 text!#?timeout=10\r\n") end # if you wish Snarl::SNP.new(@host).request("type=SNP#?version=1.1#?action=unregister#?app=Ruby-Snarl\r\n")
“rn” is must. Don’t use “rn” or “r” in message body. Use “n” instead.
require 'rubygems' require 'snarl/snp' require 'kconv' Snarl::SNP.open(@host){|snp| snp.notification('タイトル'.tosjis, '日本語'.tosjis)}
Windows encoding is required. Windows 2000 is Shift_JIS (CP932), XP is UTF-8, maybe.
bin/snarl_snp is available.
snarl_snp -H host -a app -t title -m message snarl_snp --yaml=./snp.yml
and so on.
- -H host, –host=host
-
the hostname/address which Snarl is running (default, 127.0.0.1). -h shows help. “H”ost. Sorry.
- -p port, –port=port
-
the port number which Snarl uses (default, 9887)
- -a app, –app=app
-
the application name you use on Snarl (default, nothing). It’s read in SNP#register(app)
- -c class, –class=class
-
the classname you use on Snarl (default, nothing). It’s read in SNP#add_class and notification
- -t title, –title=title
-
the title string of popup (default ‘Ruby-Snarl’).
- -m msg, –text=msg
-
the popup message body.
- -s sec, –timeout=sec
-
popups automatically close in sec (default 10 sec.). -t is not for timeout but title.
- –icon=icon_path
-
popup message icon path (default, default style’s icon). URL or filepath on Snarl machine. JPG/PNG/GIF
- –sticky
-
makes popup “sticky” (default, closes in timeout sec). this is equal to “–timeout=0”.
- -u, –unregister
-
removes app from Snarl setting window (default, false). note: users cannot change app’s setting.
- –verbose
-
shows SNP logs to stdout (default, false)
- -y yamlpath, –yaml=yamlpath
-
the YAML file path for “automatic SNP” (default, nothing)
Set Autotest::Snarl.host on “.autotest” file.
require 'snarl/autotest' Autotest::Snarl.host = '192.168.0.1'
You may set OS environment variable SNARL_HOST. Autotest::Snarl uses it instead of default host 127.0.0.1. If you use Snarl on 192.168.0.1 (and use bash as a shell),
SNARL_HOST=192.168.0.1 autotest
Copyright © 2010 kitamomonga (TATEWAKI Hiroyuki). This software is MIT license, see MIT-LICENSE file for details. Snarl and SNP is not mine. See www.fullphat.net/ .