Register now and start sharing your code snippets.
-->
Gmail checker plugin for wmii.
Ruby posted 2 months ago by marko
I take no credit for this. The original URL is http://dmy999.com/src/gmail-check.rb. The reason it is here is that I don’t want to lose it just in case the original site is taken down.
1 # 2 # gmail check plug in 3 # by Derek Young 4 # 5 # periodically read gmail's atom feed for new messages. 6 # if one is found, display the username and subject of 7 # the message. 8 # 9 # The applet wakes up after a configurable period to check (by default 10 # 3 minutes). You can also cause it to check immediately by pressing 11 # the key binding for the gmail-check binding (MODKEY-g by default). 12 # 13 # place this file in ~/.wmii-3/plugins and 14 # add the following to your wmiirc-config.rb file to enable: 15 # 16 # plugin_config["dmy999@gmail.com:gmail"]["username"] = 'my user name' 17 # plugin_config["dmy999@gmail.com:gmail"]["password"] = 'my password' 18 # plugin_config["dmy999@gmail.com:gmail"]["interval"] = 3 19 # use_bar_applet "dmy999@gmail.com:gmail", 50 20 # use_binding "dmy999@gmail.com:gmail-check" 21 # 22 # atom parsing based on code from Evan Martin 23 # http://neugierig.org/software/misc/gmail-notifier 24 # 25 # Copyright Derek Young, 2007 26 # Use as you wish but please give credit. 27 # 28 29 Plugin.define "dmy999@gmail.com" do 30 author '"Derek Young" <dmy999@gmail.com>' 31 32 def_settings "gmail/interval" do |wmii| 33 wmii.plugin_config["dmy999@gmail.com:gmail"]["interval"] = 3 * 60 34 end 35 36 CERTPATH = '/etc/ssl/certs' 37 38 # return title, email, author name of first new message 39 def gmail_check(username, password) 40 req = Net::HTTP::Get.new '/mail/feed/atom' 41 req.basic_auth(username, password) 42 43 http = Net::HTTP.new('mail.google.com', 443) 44 http.use_ssl = true 45 http.verify_mode = OpenSSL::SSL::VERIFY_PEER 46 http.ca_path = CERTPATH 47 48 res = http.request req 49 50 doc = REXML::Document.new res.body 51 entries = doc.root.get_elements('/feed/entry') 52 return nil if entries.length == 0 53 title = entries[0].elements['title'].text 54 email = entries[0].elements['author/email'].text 55 name = entries[0].elements['author/name'].text 56 [ title, email, name ] 57 end 58 59 bar_applet("gmail", 100) do |wmii, bar| 60 require 'net/https' 61 require 'rexml/document' 62 63 interval = wmii.plugin_config["dmy999@gmail.com:gmail"]["interval"] 64 username = wmii.plugin_config["dmy999@gmail.com:gmail"]["username"] 65 password = wmii.plugin_config["dmy999@gmail.com:gmail"]["password"] 66 67 @gmail_check_thread = Thread.new do 68 loop do 69 bar.data = "checking..." 70 first = gmail_check(username, password) 71 if first 72 title, email, name = first 73 user, domain = email.split('@') 74 bar.data = "#{user}:#{title}" 75 else 76 bar.data = 'no mail' 77 end 78 sleep (interval * 60) 79 end 80 end 81 end 82 83 binding("gmail-check", "MODKEY-g") do |wmii,| 84 LOGGER.info "gmail check requested" 85 @gmail_check_thread.run if @gmail_check_thread 86 end 87 88 end 89
Screenshot in wmii
Shell Script (Bash) posted about 1 year ago by marko
Method 1
A simple script to create a screenshot in wmii. It probably works in other window managers too. I call it ‘scrot’. Put it in the path and run it as you’d run any program in wmii. The “import” program comes with imagemagick.
1 #!/bin/bash 2 import -window root /tmp/screenshot.png
Method 2
If you want timestamped screenshots then
1 apt-get install scrot 2 mkdir -p ~/screenshots
And create a script with the following content for making the screenshot.
1 #!/bin/bash 2 scrot '%Y-%m-%d-%H-%M-%S_$wx$h_scrot.png' -e 'mv $f ~/screenshots'