Skip to content

Quick tip: Region Screenshot from CLI

  • by

I do mean quick

tl;dr: I use a function to quickly import a region: imp filename; drag a region, done. See below for details.


Hey you. Yes you. You like screenshots, yes? Sure you do. Everyone likes them. Reading a big wall of text: not fun, boring, you’d rather be watching the Netflix you have on in the background for noise. Reading text with images: cool, sexy, maybe the author is a secret journalist?

Also cool: short paragraphs. See?

I screenshot things a lot. I do it for posts on the blog — because per my last email, images in posts are cool and sexy — for issues on GitHub, QA posts, chat messages, saving stuff for later. All sorts of reasons, multiple times per day.

In a comment on an old post recently, Thelo asked about using ffmpeg to screenshot via kmsgrab. It’s not something I use much, but I said I’d write up what I use. (I elided a second comment about ffmpeg usage changing so the screenshot wasn’t super tall)

I have a couple of aliases for this. The most recent one I added to import to clipboard, which I mentioned before:

alias scrimp="import png:- | xclip -selection clipboard -t image/png"

But if you want to save it for longer, you want to import to a file. I wrapped the command in a tiny function so I could pass an argument easily:

imp() {
        if [ $# -eq 0 ]; then echo "usage: imp filename (no need for jpg)"; return 1; fi
        import -quality 95% /home/robert/downloads/$1.jpg
}

Example usage: imp theloscreengrab, which is exactly what I did for the image above.

That saves the image to my downloads directory (that being the directory most used by browsers, which makes it easier for uploading). 95% quality is probably a bit much for screenshots, but hey they look good.

There’s tons of GUI-based programs for this, I’ve even used some of them in the distant past. For me though, it’s hard to beat the convenience and speed of quickly alt-tabbing to a terminal window, imp screenshotname, click-drag and done.

Tell us what's on your mind

Discover more from Rob's Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading