executing hotkeys from a script into an application

Is it possible to open an application, then execute some hotkeys associated with that application using a script? For example if I wanted to open Firefox (using Firefox & for example)then I wanted to go to the Downloads tab using Ctrl + J.

Asked By: Solaire


There is a plethora of tools for this purpose, in all modern languages, like Python, Javascript, for testing and automation.

A native Linux way to do this is xdotool, which is using X11’s XTEST extension and other Xlib functions.
So it is expected to work with Gnome, KDE, Xfce4 and similar desktop environments, but not with Wayland.

A simple example to send a key to open the Downloads window for your Firefox window (modifying the README page example):

xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+Y

After installing it, man xdotool to see available actions.

Note: It’s available for macos also, as you use Ctrl+J to open Downloads Window.

Answered By: thanasisp