Close tabs in pidgin conversation window
-
28-04-2021 - |
Question
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.
Solution
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.