Jon-Michael Deldin

BMX, bike trials, & software from the Pacific Northwest

Taking a Screenshot with Just X

Working on making an ultra lean Linux machine and can’t bear the idea of installing scrot or another program for taking screenshots? Fear not! You probably already have x11-utils installed, so you can do this:

  1. xwininfo and click the window you want to take a screenshot of. This will give you the window ID. Commit this hex value to memory.
  2. import -window that_last_hex_value /tmp/screenshot.png

Or more simply, as a function:

function screenshot {
    id=$(xwininfo | fgrep 'Window id' | awk '{print $4}')
    import -window "$id" "$1"
}
screenshot /tmp/screenshot.png
* * *