Use of Shell object in Gjs
Asked Answered
R

3

11

I am writing a gtk+ app using Gjs ( Gnome JavaScript bindings ) As there are no documents available i am reading the sources of gnome-shell JavaScript's . In my app i need to get access to global.userdatadir .

I am trying to add the Shell object to my script :

const Shell = imports.gi.Shell;

and run it with #gjs myscript.js but when i do this it throws me an error saying :

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

I cant understand what's wrong with it , it is exactly as in Gnome-shell source files. Other objects are fine using imports.gi.Gio , imports.gi.GLib , works OK .

Working on Ubuntu 11.10 x64

Revocable answered 2/1, 2012 at 11:38 Comment(0)
V
7

You can't run gnome-shell extensions via gjs, they have to be loaded by gnome-shell itself. For development, this usually means putting them in ~/.local/share/gnome-shell/extensions/YOUR-EXTENSION-ID and restarting the shell.

Vestry answered 5/5, 2012 at 6:39 Comment(0)
B
3

Call org.gnome.Shell.Eval via dbus.

As gfxmonk points out, the JavaScript code should be run by the shell itself. If you’re not writing an extension, the way to do that is via dbus, for instance using systemd’s busctl. (I’m sure it’s also possible via dbus-send, I just prefer busctl’s syntax. And it has tab completion!)

For example, this logs all window titles:

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);
    }
'

You can see the log messages with journalctl /usr/bin/gnome-shell 'GLIB_DOMAIN=GNOME Shell'. (You probably want to add -b too to only see messages from the current boot, or --since '5 minutes ago', … – see journalctl(1) for more options.)

Alternatively, this GitHub gist describes how to get at the Shell module in gjs (add /usr/lib/gnome-shell to LD_LIBRARY_PATH and to GIRepository.Repository’s search path), but I haven’t managed to get access to a global object using that.


Note that since Gnome 41, calling Eval is restricted, so you’ll need to run global.context.unsafe_mode = true in Looking Glass (Alt+F2 lg) first.

Bullheaded answered 23/12, 2017 at 10:2 Comment(0)
B
2
$ 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
Banebrudge answered 20/1, 2015 at 16:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.