Managing X from the Command Line

Most of the times, I'm using a graphical interface, because having an handful of semi-overlapping urxvt windows is still better than splitting a GNU screen [1], but I don't want to leave the keyboard to reach for a mouse, hidden somewhere on my messy desktop. [2]

[1]ok, and because graphical browsers are useful :)
[2]the actual piece of wood-like stuff from IKEA and covered in paper, electronics and stuff, not the overvalued metaphor for what I don't have on my computer screen :D

Beside a properly configured window managed with lots of keyboard commands (which I have), there are command line tools that can act on GUI elements and do stuff like move windows around or even simulate mouse clicks. Unluckily some of these tools tend to work with dark magic invocations, and I can never remember how to do what I need without spending some time in the man page.

This page lists some recipes that I have needed in the past, so that I don't have to spend more time in the same manpage sections in the future. :)

This article is kept for historical reasons, but is no longer updated: see https://docs.trueelena.org/desktop/desktop_environment/index.html for up-to-date instructions.

Resizing windows

Resize all of the windows from $PROGRAM to 800x600:

xdotool search --name $PROGRAM windowsize %@ 800 600

Resize the active window to 800x600:

xdotool getactivewindow windowsize 800 600

Clipboard

Get the contents of the X selection on stdout:

xclip -o

Set MIME associations and default apps

xdg-settings is used to set some deskoppish properties and expecially the default web browser:

xdg-settings set default-web-browser xombrero.desktop

other associations can be set using xdg-mime:

xdg-mime default apvlv.desktop application/pdf

of course the .desktop can be any available file for any app, placed in one of the standard directories, either system-wide or per-user.

Both write to ~/.local/share/applications/mimeapps.list.

Send a comment: unless requested otherwise I may add it, or some extract, to this page.

Return to Top