'Running multiple xdtool commands from activateResult

I'm creating a gnome shell extension and implementing the search provider. In the activateResult method I want to run some code like

GLib.spawn_command_line_sync('xdotool windowactivate ' + window_id);
GLib.spawn_command_line_sync('xdotool key "ctrl+r"');
GLib.spawn_command_line_sync('xdotool type ' + some_text);

The problem is that only the first command works, and I get some errors like:

Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: Received a NET_CURRENT_DESKTOP message from a broken (outdated) client who sent a 0 timestamp
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: Buggy client sent a _NET_ACTIVE_WINDOW message with a timestamp of 0 for 0x2e00001 (somestuff)
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: last_focus_time (93207838) is greater than comparison timestamp (93207584).  This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW.  Trying to work around...
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: last_user_time (93207838) is greater than comparison timestamp (93207584).  This most likely represents a buggy client sending inaccurate timestamps in messages such as _NET_ACTIVE_WINDOW.  Trying to work around...
Jul 27 20:05:09 comp org.gnome.Shell.desktop[3334]: Window manager warning: 0x2e00001 (somestuff) appears to be one of the offending windows with a timestamp of 93207838.  Working around..

One thing I tried was to combine all the xdotool commands with bash -c "... ... ..." with no luck.

After selecting a search result, how can I switch to a window and simulate key presses?

(I'm brand new to gnome stuff, gjs stuff, and even JS, but, do write python daily)

edit: Just tried spawn_command_line_async and it works. Feels sloppy, someone with more experienced might have a better answer.



Solution 1:[1]

If you are writing a GNOME Shell extension, it's worth noticing that there are a number of GNOME platform libraries that you can rely on being available.

For simulating mouse and keyboard event, Atspi will work in most situations. As a simple example of simulating pressing the a key:

const Atspi = imports.gi.Atspi;

Atspi.generate_keyboard_event(0, 'a', Atspi.KeySynthType.STRING);

Activating a window, on the other hand, is probably something best done with the built-in window manager functions, however these aren't documented and you'd have to inspect the GNOME Shell JavaScript source or the source of another extension that does this.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Edvard Rejthar