How to close several tabs in a pidgin conversation window from a script (some #general
and #nickserv
tabs). I tried using xdotool
and devilspie
but no result.
Asked
Active
Viewed 416 times
2

Zsolt Botykai
- 50,406
- 14
- 85
- 110

kirill
- 211
- 4
- 10
1 Answers
4
You can use Pidgin's DBus API to close a conversation. See Pidgin's DbusHowto. The following Python code closes all conversation windows with name matching the to_close
list. (I tested this with IM usernames, but not with IRC chatroom names, so it may require some additional tweaking for your purposes.)
to_close = ["#general", "nickserv"]
for conv in purple.PurpleGetConversations():
if purple.PurpleConversationGetName(conv) in to_close:
purple.PurpleConversationDestroy(conv)
Put the following at the top of your Python file to initialize the purple
object for communicating with Pidgin/Finch over D-Bus (from the DbusHowTo):
#!/usr/bin/env python
import dbus
import sys
# Based off http://developer.pidgin.im/wiki/DbusHowto
bus = dbus.SessionBus()
obj = bus.get_object("im.pidgin.purple.PurpleService",
"/im/pidgin/purple/PurpleObject")
purple = dbus.Interface(obj, "im.pidgin.purple.PurpleInterface")
For those of you who don't like Python, here's the same thing rewritten in sh
using purple-remote
(note that for arg
iterates over the arguments to the script):
#!/bin/sh
# Note that the result of sed here is a string like "(1234) (5678)".
for conversation in `purple-remote PurpleGetConversations | sed 's/^.*[[]//' | sed 's/].*$//' | sed s/dbus.Int32//g | sed s/,//g`
do
conv_name=`purple-remote "PurpleConversationGetName$conversation"`
for arg
do
if [ "$arg" = "$conv_name" ]
then
purple-remote "PurpleConversationDestroy$conversation"
fi
done
done
I am completely unsure how brittle that pipeline of sed
s is, though. The Python seems much cleaner.

perelman
- 1,747
- 14
- 25
-
Thank you very much once again! I've said is wrong. English is not my native language. I'm rewrite your early code to the bash. I'm sorry for the trouble. P.S. Your code is better than my. – kirill Feb 15 '12 at 06:21