我正在编写一个脚本,当屏幕锁定或 gnome 屏幕保护程序激活时,它将自动将 Gnome Shell 集成聊天/消息状态更改为“不可用”。
有人知道将 gnome 消息系统状态设置为“可用”或“不可用”的终端命令是什么吗?
我曾经尝试过 pidgin 和 empathy 上的插件,但是 gnome 消息状态似乎并不依赖于这些。
答案1
让它工作了!简单的python脚本:
#!/usr/bin/python
import os
import time
import dbus
session_bus = dbus.SessionBus()
from gi.repository import TelepathyGLib as Tp
from gi.repository import GObject
loop = GObject.MainLoop()
am = Tp.AccountManager.dup()
am.prepare_async(None, lambda *args: loop.quit(), None)
loop.run()
screensaver_started = 0
running = 0
while 1:
active = 0
out = ""
pid = 0
if screensaver_started == 0:
# Don't do anything if the screensaver isn't running
s = os.popen("pidof gnome-screensaver")
spid = s.read()
s.close()
if len(spid) > 0:
screensaver_started = 1
else:
h = os.popen("gnome-screensaver-command -q", "r")
out = h.read()
active = out.find("inactive")
h.close()
if active < 0 and running == 0:
am.set_all_requested_presences(Tp.ConnectionPresenceType.OFFLINE, 'Offline', "")
running = 1
elif active > 0 and running == 1:
am.set_all_requested_presences(Tp.ConnectionPresenceType.AVAILABLE, 'available', "")
running = 0
time.sleep(3)
当屏幕锁定或屏幕保护程序激活时,此脚本将自动将状态设置为“不可用”,当屏幕保护程序关闭时,将状态恢复为可用(在线)!