kubuntu bash : Screenshot capture from command line plus upload and get the link on klipper
December 19, 2018 Leave a comment
For this article you will need klipper awk imagemagick so
sudo apt-get install gawk imagemagick
you have to test if klipper is running or not , yes you have it but probably it is not running , well to test it just do this :
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents SILLY_TEXT
now if you do paste you should get SILLY_TEST if so you are running klipper
Get a screenshot from command line :
a=/tmp/screenshot.jpeg sleep 5 import -window root -crop 1920x1080+0+100 "$a"
this command line can be easier but i will explain the complex one first :
- a it’s the name
- sleep 5 , well it actually wait for 5 seconds
- and now import it’s an imagemagick tool that let you to get a screenshot
now you can see -crop thing that i am using basically to crop automatically the picture because i have 2 monitor so i will get 1920×1080 which it’s the left screen and of course i will erase the top bar of the screen keeping the 1080 resolution
now we got the silly screenshot we have to
UPLOAD THE FILE ON IMAGEBIN.CA
well you have to register on the website after that you can get your key , go in your profile
now we can create our script
curl -s -F key="YOURSILLYKEY" \ -F file="@$1" \ https://imagebin.ca/upload.php | awk -F':' '/url:/{gsub(/url:/,"") ; print $0 }'
- the curl -s -F key=”YOURSILLYKEY” which you have to edit adding your key just send the file on imagebin.ca ,
- the awk stuff instead filter the shit curl prints just to have the link
SENT THE LINK TO KLIPPER :
qdbus org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents "$(curl -s -F key="YOURKEY" \ -F file="@$1" \ https://imagebin.ca/upload.php | awk -F':' '/url:/{gsub(/url:/,"") ; print $0 }' )"
put all in your $HOME/.bashrc
This is optional you can add this function to your bashrc and source it to get the function in your bashrc or you can create with the code a executable file and put it on ~/bin or /usr/local/bin which is better that /usr/bin that is a location for standard packages.
so
imgup(){ qdbus org.kde.klipper /klipper org.kde.klipper.klipper.setClipboardContents "$(curl -s -F key="yourkey" \ -F file="@$1" \ https://imagebin.ca/upload.php | awk -F':' '/url:/{gsub(/url:/,"") ; print $0 }' )" ## awk -F':' '/url:/{gsub(/url:/,"") ; print $0 }' }
now you can do source ~/.bashrc and it will do your job just executing : imgup