How to properly execute org.gnome.Shell.Eval with import on gnome 45

I’ve been using the following line to determine my keyboard layout

current=`gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "imports.ui.status.keyboard.getInputSourceManager()._mruSources[0]"`

after update to gnome 45, I first had to enable unsafe mode to be able to execute that, then I started getting the following output to that command:

(false, 'SyntaxError: import declarations may only appear at top level of a module')

as i understand the reason behind this is switch to “standard JavaScript modules” in gnome. As I am not really knowledgeable in javascript, I googled a bit on what is this all about, and tried to rewrite the call to return the actual result:

gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval "import('resource:///org/gnome/shell/ui/status/keyboard.js').then((module)=>{module.getInputSourceManager()._mruSources[0]})"

but that does not seem to work, as I get

(true, '{}')

I’d appreciate if someone suggests a proper way to do this.

Take a look here, maybe it helps: Failure of ALL invocations of functions from keyboard.js after switch to ESModules (#7194) · Issues · GNOME / gnome-shell · GitLab

It kind of works, it’s just not very useful.

What happens is that the code gets evaluated by gnome-shell, and the immediate result is returned via D-Bus - but in this case, the result is a Promise, not the “final” result you are expecting.

The asynchronous code still runs and completes, but as nothing uses the result anymore, in many cases it’s not very useful.

I opened this merge request to address this.

1 Like

thanks, that’s useful for extension developers, but won’t help in my case with a simple shell eval call

I see the fix is coming in gnome 46, much appreciated :slight_smile:

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.