9

I've grown affection to scrot as a simple screenshot utility, but it lacks one thing i would greatly appreciate--a way to copy your capture and have it in your clipboard automatically.

I've added a line to .bash_aliases that automatically puts it in the folder i desire, and also have it always run in selection mode, but there seems to be no flag for copying the result after capturing. Is there any way to do this?

.bash_alias entry=

alias scrot='scrot -s ~/Pictures/%b%d::%H%M%S.png'

lcdhead
  • 91
  • 1
  • 2

3 Answers3

20

Create a script file that you'll be able to easily execute:

#!/bin/sh
scrot -e 'xclip -selection clipboard -t image/png -i $f'

-t will instruct xclip it will be dealing with an image file; -i will tell xclip where the file is; $f is scrot's variable for the recent screenshot file saved.

You'll need xclip installed, but it should be readily available on your distro.

I'm using KDE Plasma now and had to resource to this approach in order to achieve Cinnamon's ready "screenshot to clipboard" hotkey.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
Gustavo Pinsard
  • 301
  • 1
  • 3
  • 1
    god that's so good, thank you – dax Jul 12 '21 at 14:30
  • 1
    This is excellent, thank you. I added this (with the -s flag) to my ~/.config/openbox/lxde-pi-rc.xml as the Execute command for the Print keybind. Now i have simple and effective selection screenshots in raspberry pi. – mynyml Aug 05 '21 at 14:27
  • 1
    If you don't want to store an image file at all, you can add ` && rm $f` to the command – lseki Jan 20 '22 at 01:10
  • i was looking for this solution for a very long time and just gave up.. now i decided to take a further look at the issue and.. boom! amazing solution! – rodolfoksveiga Jun 23 '22 at 16:00
  • work with me, ubuntu 18.04, xfce 4.12 – Tiana987642 Jul 13 '22 at 04:54
  • I wanted to avoid files and there is no special string placeholder for the actual image data, just prints to stdout without a file argument, so I used this instead: `scrot - | xclip -selection clipboard -t image/png`. In my i3 config just wrapped that in `fish -c '...'` to use the pipe. – Pysis Nov 29 '22 at 18:36
1

If you want to run it through pngquant first and then pass it to the clipboard, do this:

#!/bin/sh
scrot -s "$HOME/Pictures/Screenshot_%Y-%m-%d_%H.%M.%S.png" -e 'pngquant $f; xclip -selection clipboard -t image/png -i `echo $f | cut -d"." -f-3`-fs8.png'
0

You can also try the gnome-screenshot utility.

gnome-screenshot -acf /tmp/my-screenshot && cat /tmp/my-screenshot | xclip -i -selection clipboard -target image/png
Jobin
  • 141
  • 2