我正在创建gnome shell扩展名并实现搜索提供商。在Activateresult方法中,我想运行一些代码,例如
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);
问题是只有第一个命令有效,我会得到一些错误:
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..
我尝试的一件事是将所有Xdotool命令与bash -c "... ... ..."
相结合而没有运气。
选择搜索结果后,如何切换到窗口并模拟按键按下?
(我是Gnome东西,GJS的东西,甚至JS的新手,但是,每天写Python(
编辑:刚刚尝试了spawn_command_line_async
,并且可以正常工作。感到草率,经验丰富的人可能有更好的答案。
如果您正在编写GNOME shell扩展名,则值得注意的是,您可以依靠许多gnome平台库。
对于模拟鼠标和键盘事件,ATSPI将在大多数情况下工作。作为模拟按a
键的简单示例:
const Atspi = imports.gi.Atspi;
Atspi.generate_keyboard_event(0, 'a', Atspi.KeySynthType.STRING);
另一方面,激活窗口可能是内置窗口管理器功能最好的事情,但是这些窗口没有记录,您必须检查Gnome shell JavaScript源或其他扩展名的源这样做。