1

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 ?

zx485
  • 2,426
George
  • 21

3 Answers3

2

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
pLumo
  • 26,947
  • Worked like a charm! But I'm not getting what -b ( grab wm border too ) does – George Sep 10 '21 at 13:23
  • 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 you linked. – pLumo Sep 10 '21 at 13:46
  • 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 – George Sep 12 '21 at 03:42
1

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.

vanadium
  • 88,010
  • 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 – George Sep 10 '21 at 12:59
  • @Yury so maybe just gnome-screenshot -c && gnome-screenshot -f filename ? – raj Sep 10 '21 at 13:07
  • 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 Sep 10 '21 at 13:07
  • Tested this also on 20.04 now. – vanadium Sep 10 '21 at 13:15
  • With just 2 repeated calls to 'gnome-screenshot' with -a option one would have to select area twice. – George Sep 10 '21 at 13:16
  • 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 – George Sep 10 '21 at 13:20
  • @vanadium Could you specify your version of gnome-screenshot ? Maybe I can try it instead – George Sep 12 '21 at 02:37
  • The version that comes with Ubuntu 20.04. – vanadium Sep 13 '21 at 10:07
1

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

George
  • 21