Score:0

How to save screenshot both to clipboard and disk?

mz flag

I am trying achieve such behavior that screenshot is saved both to the disk and to clipboard. Been digging through these questions, but it's not coming together.

What is the terminal command to take a screenshot?
What is the command line equivalent of copying a file to clipboard?

Main problem being that I can't really copy the image to the clipboard to paste it with Ctrl+V.
Is there anything else I might want to consider ?

Score:1
in flag

You can just add the xclip command to scrot -e:

scrot '%F_%T.png' -e 'xclip -selection clip -t image/png "$f"; mv "$f" ~/Desktop/'

Of course you don't need to move the file to the Desktop, it's just an example how to combine multiple commands ...

You might need to install scrot:

sudo apt install scrot
Yury avatar
mz flag
Worked like a charm! But I'm not getting what -b ( grab wm border too ) does
pLumo avatar
in flag
Probably you can simply leave it out ... Might be useful for themes with window borders when you just grab a single window ;-) Copied it from [one of the answers](https://askubuntu.com/a/194438/631600) you linked.
Yury avatar
mz flag
Turned out, this does not always work, when bound to a shortuct for some reason, and also there is a chance of framing getting in the way
Score:1
cn flag

Assuming you use the default Ubuntu desktop, just combine two options of the gnome-screenshot command for sending to the clipboard and to a file:

gnome-screenshot -c -f file.png

This will send the output to the clipboard and to a file, in this example in your Pictures folder, named according to the timestamp given by the date -Ins command.

Yury avatar
mz flag
`gnome-screenshot` would be ideal, but -c and -f don't seem to work together for me, file is not being saved with -c present
raj avatar
cn flag
raj
@Yury so maybe just `gnome-screenshot -c && gnome-screenshot -f filename` ?
vanadium avatar
cn flag
I noted I forgot a / and an extension. Try the updated command. Files of your previous attempt will be in your current working directory, name starting with Pictures, but without extension.
vanadium avatar
cn flag
Tested this also on 20.04 now.
Yury avatar
mz flag
With just 2 repeated calls to 'gnome-screenshot' with -a option one would have to select area twice.
Yury avatar
mz flag
I'm using 18.04.05 with `gnome-screenshot is already the newest version (3.25.0-0ubuntu2)` and -c option prevents file from saving anywhere
Yury avatar
mz flag
@vanadium Could you specify your version of `gnome-screenshot` ? Maybe I can try it instead
vanadium avatar
cn flag
The version that comes with Ubuntu 20.04.
Score:0
mz flag

I want to thank both @vanadium and @pLumo for their answers, which were very helpful, but both of used utilities have their own disadvantages and bugs at least on my system, so I finally went with combination of two approaches

#!/bin/bash

OUT_FILENAME=Screenshot from $(date "+%Y-%m-%d-%H-%M-%S").png
OUT_PATH=~/Pictures/$OUT_FILENAME

gnome-screenshot -a -f $OUT_PATH
xclip -sel clip < /dev/null
xclip -selection clip -t image/png $OUT_PATH

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.