···11+#!/usr/bin/ruby
22+#
33+# pidgin_status.rb
44+# a d-bus script to set your pidgin status and optional status message
55+#
66+# Copyright (c) 2008, 2010 joshua stein <jcs@jcs.org>
77+#
88+# Redistribution and use in source and binary forms, with or without
99+# modification, are permitted provided that the following conditions
1010+# are met:
1111+#
1212+# 1. Redistributions of source code must retain the above copyright
1313+# notice, this list of conditions and the following disclaimer.
1414+# 2. Redistributions in binary form must reproduce the above copyright
1515+# notice, this list of conditions and the following disclaimer in the
1616+# documentation and/or other materials provided with the distribution.
1717+# 3. The name of the author may not be used to endorse or promote products
1818+# derived from this software without specific prior written permission.
1919+#
2020+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
2121+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2222+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2323+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2424+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2525+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2626+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2727+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2828+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2929+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030+#
3131+3232+require "dbus"
3333+3434+# magic!
3535+STATUS_AVAILABLE = 2
3636+STATUS_AWAY = 5
3737+3838+status = case ARGV[0].to_s
3939+when "away"
4040+ STATUS_AWAY
4141+when "available"
4242+ STATUS_AVAILABLE
4343+else
4444+ STDERR.puts "usage: #{$0} <available|away> <optional message>"
4545+ exit -1
4646+end
4747+4848+message = ARGV[1]
4949+5050+sb = DBus::SessionBus.instance
5151+if !sb.proxy.ListNames.first.include?("im.pidgin.purple.PurpleService")
5252+ STDERR.puts "pidgin not running, exiting"
5353+ exit -1
5454+end
5555+5656+pd = sb.service("im.pidgin.purple.PurpleService")
5757+pidgin = pd.object("/im/pidgin/purple/PurpleObject")
5858+pidgin.default_iface = "im.pidgin.purple.PurpleInterface"
5959+6060+pidgin.introspect
6161+6262+if (ss = pidgin.PurpleSavedstatusGetCurrent()).is_a? Array
6363+ if pidgin.PurpleSavedstatusGetType(ss.first).first == status
6464+ # already away or available, don't change
6565+ exit
6666+ end
6767+6868+ ps = pidgin.PurpleSavedstatusNew("", status).first
6969+ pidgin.PurpleSavedstatusSetMessage(ps, message.to_s)
7070+ pidgin.PurpleSavedstatusActivate(ps)
7171+end