关闭洋泾浜对话窗口中的选项卡

发布于 2024-12-26 10:26:47 字数 142 浏览 0 评论 0原文

如何从脚本关闭洋泾浜对话窗口中的多个选项卡(一些 #general#nickserv 选项卡)。我尝试使用 xdotooldevilspie 但没有结果。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2025-01-02 10:26:47

您可以使用 Pidgin 的 DBus API 来关闭对话。请参阅 Pidgin 的 DbusHowto。以下 Python 代码关闭名称与 to_close 列表匹配的所有对话窗口。 (我使用 IM 用户名进行了测试,但没有使用 IRC 聊天室名称进行了测试,因此可能需要根据您的目的进行一些额外的调整。)

to_close = ["#general", "nickserv"]
for conv in purple.PurpleGetConversations():
    if purple.PurpleConversationGetName(conv) in to_close:
        purple.PurpleConversationDestroy(conv)

将以下内容放在 Python 文件的顶部,以初始化 purple 对象:通过 D-Bus 与 Pidgin/Finch 进行通信(来自 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")

对于那些不这样做的人不喜欢 的参数):

#!/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

Python,这是使用 purple-remotesh 中重写的相同内容(请注意,for arg 迭代脚本 不过,完全不确定 sed 的管道有多脆弱。 Python 看起来更干净。

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 seds is, though. The Python seems much cleaner.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文