Marcio Cunha

How to organize windows and shortcuts in Ubuntu with xdotool

Learn how to control window positioning and create custom shortcuts in Ubuntu using simple xdotool scripts and terminal commands.

Marcio Cunha•4 min
Also available in:PortuguêsEspañol
Summary
  • The xdotool utility simulates keyboard and mouse inputs, allowing programmatic window management on Linux.
  • Identifying a specific window ID is the primary step required to resize and position it via script.
  • Complex layout commands can be easily mapped to global keyboard shortcuts within the graphical environment.
  • Automation routines eliminate repetitive clicking and optimize your daily workflow across multiple monitors.
  • Combining terminal tools with window managers grants complete control over your working desktop space.

What is xdotool and why use it for visual automation

Managing multiple open windows on your screen every day can become an exhausting task, especially when you need to align editors, browsers, and terminals into precise positions. In the Linux ecosystem, the xdotool command acts as an invisible automaton for the graphical environment, letting you simulate mouse clicks, keyboard typing, and window movements directly from the terminal. In practice, this means you can write small script routines to organize your entire workspace in seconds, saving precious clicks and keeping your focus on what matters. This approach is fantastic for productivity enthusiasts and complements other desktop optimization workflows, much like learning how to organize windows in Windows with keyboard shortcuts if you frequently switch between different operating systems.

How to install and verify basic operation of the tool

Before automating anything, we need to ensure the utility is properly installed on your operating system. Ubuntu and the vast majority of Linux distributions include this library in their official repositories, making installation straightforward via a single rapid terminal command. To install it, simply open your command line interface and run the standard package manager instruction. Once installed, you can perform quick tests to verify if the program successfully interacts with your current graphical server, which controls window rendering on your display.

  1. Open the Ubuntu terminal by pressing the Ctrl, Alt, and T keys simultaneously.
  2. Run the installation command by typing
    sudo apt update && sudo apt install xdotool -y
    and enter your password when prompted.
  3. Test the installation by checking the current tool version with the command
    xdotool version
    in the command line.

Identifying windows and discovering their unique identifiers

For the computer to move or resize a specific window, it must know exactly who is who among the stack of running applications on your desktop. Each active window has a unique identification number called an ID, which acts as a digital ID card for the operating system. Using the xdotool search command, you can look up applications by part of their title—such as a browser or text editor name—and automatically capture this number. When we combine this search with resizing commands, we completely eliminate the need to use the mouse to drag borders and align pixels manually every single day.

Creating commands to resize and position windows

With the window identifier in hand, automation magic truly happens through mathematical parameters that define screen coordinates and pixel dimensions. The windowmove command places the top-left corner of the window at specific X and Y monitor coordinates, while windowsize sets the exact width and height the application should occupy. In practice, if you own a large monitor, you can write a script that snaps your browser to the left half and your terminal to the right half with a single command. This level of customization mirrors the agility we seek when figuring out how to merge PDF files on Linux using the terminal to handle bureaucratic tasks at lightning speed.

Writing a shell script to automate your daily routine

Instead of typing several long commands into the terminal every time you turn on your computer, we can bundle everything into an executable script file. A shell script is essentially a list of instructions that the terminal reads and executes line by line in a sequential, automated fashion. We can create a file named organize.sh, insert the instructions to launch our favorite applications, wait a few seconds for them to fully load, and then position each one in its proper place on screen. This routine eliminates startup friction and guarantees your desktop environment is structured exactly how you like it without manual effort.

#!/bin/bash
# Launches browser and terminal in specific positions
google-chrome &
sleep 1
WID=$(xdotool search --class "google-chrome" | head -n 1)
xdotool windowmove $WID 0 0
xdotool windowsize $WID 960 1080

gnome-terminal &
sleep 1
WID_TERM=$(xdotool search --class "gnome-terminal-server" | head -n 1)
xdotool windowmove $WID_TERM 960 0
xdotool windowsize $WID_TERM 960 1080

Binding scripts to global keyboard shortcuts in Ubuntu

A perfect script loses some of its utility if you have to open the terminal and type its name every time you want to use it. The secret to turning this into a fluid habit is binding your custom script to a global keyboard combination in the operating system, such as Ctrl + Alt + O. In Ubuntu settings, under the keyboard shortcuts section, you can add a custom shortcut pointing directly to the path of the executable file we created earlier. Thus, whenever chaos strikes your screen with scattered windows, you simply press your magic shortcut and let the system put everything back in order instantly. To explore these architectural concepts further in production, see our related technical analysis on How to test OLED display with oscilloscope and find faults.

Final thoughts on productivity through visual automation

Automating minor graphical interface details with xdotool transforms how we interact with the Linux operating system daily. Although modern tiling window managers offer complex native features, mastering simple scripts gives you total freedom to create tailored solutions without changing your entire desktop environment. Investing a few minutes to build these visual triggers pays off in hours of preserved focus throughout the week, reducing the mental fatigue caused by repetitive screen organization tasks.