I want to control chromium file chooser dialog without any human intervention on Linux.
I am trying to achieve it with at-spi2 and python. (at-spi2 python binding that made by gobject-intropection)
I would like to show an textbox to enter the file path directly with Ctrl-L.
But I have no idea how to send Ctrl-L to the file chooser dialog box.
Edit
I thought it only happens in Chromium, But actually it happens not only chromium but also all of others like zenity.
Now I know the dialog box do not belong under the chromium, actually it is controlled by xdg-desktop-portal-gnome.
How I can do it?
My environment is ArchLinux and Gnome 45, Chromium 122.0.6261.94 (Official Build)
The following code is I tried send keyboard input with generate_keyboard_event, but nothing to happen...
def search_chrome_filechooser():
if not Atspi.is_initialized():
err = Atspi.init()
if err != 0:
print("Something Error:", err)
return
root = Atspi.get_desktop(0)
app = search_widget(root, "xdg-desktop-portal-gnome", "application")
if app == None:
print("app not found")
return
dialog = search_widget(app, role_name="dialog")
if dialog is None:
print("file chooser dialog not found")
if Atspi.is_initialized():
Atspi.exit()
return
Atspi.generate_keyboard_event(29, None, Atspi.KeySynthType.PRESS)
Atspi.generate_keyboard_event(38, None, Atspi.KeySynthType.PRESSRELEASE)
if Atspi.is_initialized():
Atspi.exit()
def search_widget(root, name: str|None=None, role_name:str|None=None):
widget = root
if widget == None:
return None
if name == None and role_name == None:
return
widget_name = widget.get_name()
widget_role_name = widget.get_role_name()
if name == widget_name and role_name == None:
return widget
elif name == None and role_name == widget_role_name:
return widget
elif name == widget_name and role_name == widget_role_name:
return widget
num = widget.get_child_count()
for v in range(num):
child = widget.get_child_at_index(v)
if (result := search_widget(child, name, role_name)) != None:
return result
search_chrome_filechooser()
This is the script which works when File Chooser has focus, I'm on Ubuntu/Gnome/Wayland:
To move focus, try this :
My xdotool version