awesomeWM: bind Print Screen key to take screenshots
First, create a directory called ~/bin
where you will put the script that the Print Screen key will call:
$ cd
$ mkdir ~/bin
Move to that directory:
$ cd bin
Create a file where you’ll paste the script:
$ touch capscr
Also, you might need to install imagemagick:
$ sudo apt install imagemagick
Paste the script in the file capscr
:
#!/bin/bash
# author: nixkid
timestamp="$(date +%d.%m.%Y"_shot_"%H:%M:%S)"
targetbase="$HOME/Pictures/screenshots"
mkdir -p $targetbase
[ -d $targetbase ] || exit 1
import -window root -quality 98 $targetbase/$timestamp.png
Make the script executable:
~/bin$ chmod +x capscr
Create a folder where screenshots will be saved, mine is in ~/Pictures:
$ mkdir ~/Pictures/screenshots
The script will create ~/Picture/screenshots
.
Now you need to tell awesome to bind the key PrtSc
to the script capscr
.
$ cd ~/.config/awesome
where rc.lua
is, that is awesome’s configuration file.
You can skip these steps if you want.
These are steps you can take so you can restore rc.lua
if you mess things up.
Initiate a repository and commit.
$ git init
$ git add .
$ git commit -m "First commit"
Now, if you mess up your rc.lua
file you can run $ git checkout .
to restore the file to where it was when you ran $ git commit -m “First commit”
.
You’ll need to modify rc.lua
to tell awesome to connect the key PrtSc
and the script capscr
.
I wrote a patch you can use to modify rc.lua
.
To download the patch in ~/.config/awesome
you need wget:
$ sudo apt install wget # to install wget first
Then, download the patch in awesome configuration directory:
$ wget https://yctct.com/_bind_PrtSc_capture_screen.patch
Apply the patch to your rc.lua
config file:
$ patch -i _bind_PrtSc_capture_screen.patch
The patch should be applied; if you use git you can run $ git diff
to see.
Once you’ve applied the patch you can restart awesome:
$ echo 'awesome.restart()' | awesome-client
Press the key PrtSc
.
A screenshot should be saved in ~/Pictures/screenshots
.
Now that rc.lua
is patched, you can remove the file containing the patch:
~/.config/awesome$ rm -i _bind_PrtSc_capture_screen.patch
If you use git:
$ git add rc.lua
$ git commit -m "Apply prtsc patch"
You can remove the patch by deleting the commit.
Ref: https://imagemagick.org/script/import.php
personal computing command-line interface (cli) gnu linux trisquel shell literacy wiki awesomewm