gnome-shell - Gjs中Shell对象的使用

标签 gnome-shell

我正在使用 Gjs(Gnome JavaScript 绑定(bind))编写一个 gtk+ 应用程序
由于没有可用的文档,我正在阅读 gnome-shell JavaScript 的源代码。
在我的应用程序中,我需要访问 global.userdatadir .

我正在尝试将 Shell 对象添加到我的脚本中:

const Shell = imports.gi.Shell;

并使用 #gjs myscript.js 运行它
但是当我这样做时,它会抛出一个错误:
JS ERROR: !!!   Exception was: Error: Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found
    JS ERROR: !!!     lineNumber = '0'
    JS ERROR: !!!     fileName = '"gjs_throw"'
    JS ERROR: !!!     stack = '"("Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found")@gjs_throw:0
@manager.js:5
"'
    JS ERROR: !!!     message = '"Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found"'
Error: Requiring Shell, version none: Typelib file for namespace 'Shell' (any version) not found

我无法理解它有什么问题,它与 Gnome-shell 源文件中的完全一样。
其他对象可以使用 imports.gi.Gio , imports.gi.GLib ,工作正常。

在 Ubuntu 11.10 x64 上工作

最佳答案

调用 org.gnome.Shell.Eval通过 dbus。

正如 gfxmonk 指出的那样,JavaScript 代码应该由 shell 本身运行。如果您不编写扩展,则可以通过 dbus,例如使用 systemd 的 busctl . (我确定也可以通过 dbus-send ,我只是更喜欢 busctl 的语法。它有制表符完成!)

例如,这会记录所有窗口标题:

busctl --user call org.gnome.Shell /org/gnome/Shell org.gnome.Shell Eval s '
    for (const actor of global.get_window_actors()) {
        const window = actor.get_meta_window(),
              title = window.get_title();
        log(title);
    }
'

您可以使用 journalctl /usr/bin/gnome-shell 'GLIB_DOMAIN=GNOME Shell' 查看日志消息. (您可能还想添加 -b 以仅查看来自当前引导的消息,或 --since '5 minutes ago' ,... – 请参阅 journalctl (1) 了解更多选项。)

或者,this GitHub gist描述如何到达 Shell gjs 中的模块(添加 /usr/lib/gnome-shellLD_LIBRARY_PATHGIRepository.Repository 的搜索路径),但我还没有设法访问 global使用它的对象。

关于gnome-shell - Gjs中Shell对象的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8700347/

相关文章:

linux - gnome shell 3.16 - 如何添加重启按钮

gnome - 用 Onboard -> Hide/Show via DBus 替换 Gnomes 虚拟键盘不起作用

ubuntu - 如何在 gnome shell 的 libnotify 中自动隐藏错误消息?

menu - 窗外的 Gtk3 Popover

sudo - gksudo 替代 gnome 3

gnome-shell - metadata.json 中的 "shell-versions"变量到底是如何工作的?

javascript - 在 Gnome Shell >= 3.16(自定义扩展)中设置通知图标

Java SystemTray 图标并不总是有效

javascript - GNOME 中鼠标进入屏幕特定像素范围时的激活方法

gnome - 如何在 gjs 中使用 "lang"?