dbus ruby script to set away/available status in pidgin

add

jcs.org a6337f12

+71
+71
pidgin_status.rb
··· 1 + #!/usr/bin/ruby 2 + # 3 + # pidgin_status.rb 4 + # a d-bus script to set your pidgin status and optional status message 5 + # 6 + # Copyright (c) 2008, 2010 joshua stein <jcs@jcs.org> 7 + # 8 + # Redistribution and use in source and binary forms, with or without 9 + # modification, are permitted provided that the following conditions 10 + # are met: 11 + # 12 + # 1. Redistributions of source code must retain the above copyright 13 + # notice, this list of conditions and the following disclaimer. 14 + # 2. Redistributions in binary form must reproduce the above copyright 15 + # notice, this list of conditions and the following disclaimer in the 16 + # documentation and/or other materials provided with the distribution. 17 + # 3. The name of the author may not be used to endorse or promote products 18 + # derived from this software without specific prior written permission. 19 + # 20 + # THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR 21 + # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 + # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 + # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 + # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 + # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 + # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 + # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 + # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 + # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 + # 31 + 32 + require "dbus" 33 + 34 + # magic! 35 + STATUS_AVAILABLE = 2 36 + STATUS_AWAY = 5 37 + 38 + status = case ARGV[0].to_s 39 + when "away" 40 + STATUS_AWAY 41 + when "available" 42 + STATUS_AVAILABLE 43 + else 44 + STDERR.puts "usage: #{$0} <available|away> <optional message>" 45 + exit -1 46 + end 47 + 48 + message = ARGV[1] 49 + 50 + sb = DBus::SessionBus.instance 51 + if !sb.proxy.ListNames.first.include?("im.pidgin.purple.PurpleService") 52 + STDERR.puts "pidgin not running, exiting" 53 + exit -1 54 + end 55 + 56 + pd = sb.service("im.pidgin.purple.PurpleService") 57 + pidgin = pd.object("/im/pidgin/purple/PurpleObject") 58 + pidgin.default_iface = "im.pidgin.purple.PurpleInterface" 59 + 60 + pidgin.introspect 61 + 62 + if (ss = pidgin.PurpleSavedstatusGetCurrent()).is_a? Array 63 + if pidgin.PurpleSavedstatusGetType(ss.first).first == status 64 + # already away or available, don't change 65 + exit 66 + end 67 + 68 + ps = pidgin.PurpleSavedstatusNew("", status).first 69 + pidgin.PurpleSavedstatusSetMessage(ps, message.to_s) 70 + pidgin.PurpleSavedstatusActivate(ps) 71 + end