我想(以编程方式)访问 GNOME 3.6 下 Ubuntu 平视显示器 (HUD) 菜单服务的结果。我一直在尝试使用 HUD 的 DBus 接口(interface)并取得了一些成功,但无法让它在 Unity 之外工作。例如,以下 Python 脚本在登录到 Unity 后从终端运行时会显示一些结果:
#!/usr/bin/env python
import dbus
session_bus = dbus.SessionBus()
proxy_obj = session_bus.get_object('com.canonical.hud', '/com/canonical/hud')
hud_iface = dbus.Interface(proxy_obj, dbus_interface='com.canonical.hud')
query_result = hud_iface.StartQuery("ope", 5)
for res in query_result[1]:
print res[0].encode('utf8')
hud_iface.CloseQuery(query_result[2])
在 Unity 下运行它(在 12.10 中)我得到:
$ ./hud.py
File > <b>Open</b> Tab
File > <b>Open</b> Terminal
dropbox > <b>Open</b> Dropbox Folder
View > Zoom <b>Out</b>
Terminal > Set Character Encoding > Add <b>or</b> Remove…
...但是在 GNOME 3.6 下我没有得到任何结果(没有错误,什么都没有)。
看起来涉及这些服务,因为它们一直在 Unity 而不是 GNOME 下运行:
/usr/lib/indicator-appmenu/hud-service
/usr/lib/x86_64-linux-gnu/indicator-application-service
/usr/lib/indicator-(whatever)/indicator-(whatever)-service
但是如果我在 GNOME 下启动它们,它们很快就会退出
$ /usr/lib/indicator-session/indicator-session-service
(process:4921): libindicator-WARNING **: No watchers, service timing out.
如果我设法在那个狭窄的时间窗口内运行我的脚本,那么我就会得到结果!但是我如何让这些服务保持运行呢?是什么首先启动了它们?它们是否包含应用程序菜单内容,还是由其他服务提供?
最佳答案
您似乎使用了错误的服务名称。我现在没有可用的 GNOME 3.6,但是你可以使用 列出 dbus 服务
dbus-send --session --dest=org.freedesktop.DBus --type=method_call --print-reply /org/freedesktop/DBus org.freedesktop.DBus.ListNames
此外,您应该在启动 Gnome 之前export UBUNTU_MENUPROXY=libappmenu.so
,或者在 /etc/environment 中定义它
同时检查您是否安装了 indicator-appmenu .
但是在阅读这里之后here ,我猜 GNOME 桌面没有使用这样的服务:
因此我确认您应该寻找另一个特定于 Gnome 的 DBus 服务(具有不同的 API)。
关于ubuntu - 如何从 GNOME 下的 HUD DBus 服务获取结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15328506/