我正在使用Gjs (绑定)编写一个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都很好,工作正常。
在Ubuntu11.10 x64上工作
发布于 2012-05-05 14:39:21
您不能通过gjs运行gnome-shell扩展,它们必须由gnome-shell本身加载。对于开发,这通常意味着将它们放入~/.local/share/gnome-shell/extensions/YOUR-EXTENSION-ID并重启外壳。
发布于 2015-01-21 00:58:51
$ apt-file search -x "Shell.*typelib"
gnome-shell: /usr/lib/gnome-shell/Shell-0.1.typelib
gnome-shell: /usr/lib/gnome-shell/ShellJS-0.1.typelib
gnome-shell: /usr/lib/gnome-shell/ShellMenu-0.1.typelib
$ sudo apt-get install gnome-shell发布于 2017-12-23 18:02:18
通过dbus调用org.gnome.Shell.Eval 。
正如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描述了如何获取gjs中的Shell模块(将/usr/lib/gnome-shell添加到LD_LIBRARY_PATH和GIRepository.Repository的搜索路径中),但我还没有设法使用它访问global对象。
https://stackoverflow.com/questions/8700347
复制相似问题