pmss (Poor Man's Screenshooter)

hakerdefo



20-03-2017 UPDATE BEGINS

V4 at your service. Grab it from here,

pmss V4

Cheers!!!

20-03-2017 UPDATE ENDS





CHRISTMAS UPDATE BEGINS

Version 3 of pmss is here,

http://vsido.org/index.php?topic=1237.msg14041#msg14041

Cheers & Merry Christmas To You All  :)

CHRISTMAS UPDATE ENDS





UPDATE BEGINS

A new and improved version of pmss can be found here,

http://vsido.org/index.php?topic=1237.msg13959#msg13959

Cheers!!!

UPDATE ENDS



It is what the title says  :D
I'm in a bit of a hurry so description & detail will follow a bit later  ;)
Try it! It has a very good upload function that can make sharing scrrenshots easy-peasy  8)


#!/usr/bin/env bash

function bye_bye (){
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"A screenshot is an image of the display on a computer screen."
echo -e '\E[1;32;49m'"But you already knew that so,"
echo -e '\E[1;32;49m'"Bye, Ciao, Adios."
echo -e ""
sleep 4
printf "\033c"
tput sgr0
exit 0
}

function imgur_upload (){
type curl >/dev/null 2>&1
RETVAL=$?
if [[ ! "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"pmss requires \"cURL\" to upload to imgur."
echo -e '\E[1;32;49m'"Install \"curl\" via your package-manager."
echo -e ""
fi
printf "\033c"
response=$(curl -s --connect-timeout 30 --user-agent "Mozilla/5.0 Gecko/20100101" -H "Authorization: Client-ID $client_id" -H "Expect: " -F "image=@$NAME" https://api.imgur.com/3/image.xml 2>/dev/null)
RETVAL=$?
if [[ ! "$RETVAL" == 0 ]]; then
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"pmss cannot connect to \"imgur\"."
echo -e '\E[1;32;49m'"Check your internet connection."
echo -e ""
tput sgr0
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
else
URL3="${response##*<link>}"
URL2="${URL3%%</link>*}"
URL=$(echo "$URL2" 2>/dev/null | sed 's/^http:/https:/')
BASE_URL="${URL%.*}"
BASE_EXT="${URL##*.}"
DEL_HASH2="${response##*<deletehash>}"
DEL_HASH="${DEL_HASH2%%</deletehash>*}"
DEL_URL="https://imgur.com/delete/$DEL_HASH"
printf "\033c"
echo -e '\E[1;32;49m'"DIRECT LINK"
echo -e '\E[1;32;49m'"Original  : "'\E[0;32;49m'"$URL"
echo -e '\E[1;32;49m'"Thumbnail : "'\E[0;32;49m'""$BASE_URL"m."$BASE_EXT""
echo -e ""
echo -e '\E[1;32;49m'"BBCODE (FORUMS, MESSAGE BOARDS, ETC.)"
echo -e '\E[1;32;49m'"Original  : "'\E[0;32;49m'"[img]$URL[/img]"
echo -e '\E[1;32;49m'"Thumbnail : "'\E[0;32;49m'"[url=$BASE_URL][img]"$BASE_URL"m."$BASE_EXT"[/img][/url]"
echo -e ""
echo -e '\E[1;32;49m'"MARKDOWN (REDDIT, GITHUB, ETC.)"
echo -e '\E[1;32;49m'"Original  : "'\E[0;32;49m'"[$SHORT_NAME]($URL)"
echo -e '\E[1;32;49m'"Thumbnail : "'\E[0;32;49m'"[$SHORT_NAME]("$BASE_URL"m."$BASE_EXT")"
echo -e ""
echo -e '\E[1;32;49m'"HTML (WEBSITES, BLOGS, ETC.)"
echo -e '\E[1;32;49m'"Original  : "'\E[0;32;49m'"<a href="$BASE_URL"><img src="$URL" title="source: imgur.com" /></a>"
echo -e '\E[1;32;49m'"Thumbnail : "'\E[0;32;49m'"<a href="$BASE_URL"><img src=""$BASE_URL"m."$BASE_EXT"" title="source: imgur.com" /></a>"
echo -e ""
echo -e '\E[1;32;49m'"IMAGE DELETE LINK"
echo -e '\E[1;32;49m'"Delete url: "'\E[0;32;49m'"$DEL_URL"
echo -e ""
tput sgr0
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
fi
}

function area_mouse (){
printf "\033c"
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"
echo -e ""
echo -e '\E[1;32;49m'"Draw A Rectangle On The Screen And Area Inside It Will Be Captured.."
echo -e ""
scrot -s "${NAME}"
printf "\033c"
echo -e ""
echo -e '\E[0;32;49m'"$SHORT_NAME"'\E[1;32;49m'" Saved in "'\E[0;32;49m'"$DIR"
echo -e ""
type xdg-open >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
xdg-open "${NAME}"
else
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"pmss unable to open saved shot."
echo -e '\E[1;32;49m'"Install \"xdg-utils\" to do this."
echo -e ""
fi
echo -e ""
echo -e '\E[1;32;49m'"Would you like to upload the shot to imgur?"
echo -e ""
echo -e '\E[1;32;49m'"Press \"Y\" to upload the shot to imgur"
echo -e '\E[1;32;49m'"Press \"N\" to go back to the main menu"
echo -e ""
echo -e '\E[1;32;49m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
imgur_upload
;;
"N" | "n")
printf "\033c"
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32;49m'"Correct Options To Choose Are From Y-N"
echo -e ""
echo -e '\E[1;32;49m'"To upload image to imgur, press \"Y\""
echo -e '\E[1;32;49m'"To go back the main menu, press \"N\""
echo -e '\E[1;32;49m'"Got it? It is not that hard you see"
echo -e ""
tput sgr0
read -r -s -p $'Press Any Key To Continue...\n' -n1
MenU
;;
esac
}

function window_focus (){
printf "\033c"
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"
echo -e ""
echo -e '\E[1;32;49m'"Minimize Terminal And Bring The Window To Be Captured In Focus.."
echo -e ""
scrot -u -d10 -b -c "${NAME}"
printf "\033c"
echo -e ""
echo -e '\E[0;32;49m'"$SHORT_NAME"'\E[1;32;49m'" Saved in "'\E[0;32;49m'"$DIR"
echo -e ""
type xdg-open >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
xdg-open "${NAME}"
else
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"pmss unable to open saved shot."
echo -e '\E[1;32;49m'"Install \"xdg-utils\" to do this."
echo -e ""
fi
echo -e ""
echo -e '\E[1;32;49m'"Would you like to upload the shot to imgur?"
echo -e ""
echo -e '\E[1;32;49m'"Press \"Y\" to upload the shot to imgur"
echo -e '\E[1;32;49m'"Press \"N\" to go back to the main menu"
echo -e ""
echo -e '\E[1;32;49m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
imgur_upload
;;
"N" | "n")
printf "\033c"
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32;49m'"Correct Options To Choose Are From Y-N"
echo -e ""
echo -e '\E[1;32;49m'"To upload image to imgur, press \"Y\""
echo -e '\E[1;32;49m'"To go back the main menu, press \"N\""
echo -e '\E[1;32;49m'"Got it? It is not that hard you see"
echo -e ""
tput sgr0
read -r -s -p $'Press Any Key To Continue...\n' -n1
MenU
;;
esac
}

function entire_area (){
printf "\033c"
DATE="$(date +%d%m%y-%H%M%S)"
SHORT_NAME="Shot-${DATE}.png"
NAME="${DIR}/${SHORT_NAME}"
echo -e ""
echo -e '\E[1;32;49m'"Minimize Terminal To Avoid It From Being Captured.."
echo -e ""
scrot -d10 -c "${NAME}"
printf "\033c"
echo -e ""
echo -e '\E[0;32;49m'"$SHORT_NAME"'\E[1;32;49m'" Saved in "'\E[0;32;49m'"$DIR"
echo -e ""
type xdg-open >/dev/null 2>&1
RETVAL=$?
if [[ "$RETVAL" == 0 ]]; then
xdg-open "${NAME}"
else
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"pmss unable to open saved shot."
echo -e '\E[1;32;49m'"Install \"xdg-utils\" to do this."
echo -e ""
fi
echo -e ""
echo -e '\E[1;32;49m'"Would you like to upload the shot to imgur?"
echo -e ""
echo -e '\E[1;32;49m'"Press \"Y\" to upload the shot to imgur"
echo -e '\E[1;32;49m'"Press \"N\" to go back to the main menu"
echo -e ""
echo -e '\E[1;32;49m'"Enter Your Choice: "
echo -e ""
tput sgr0
read -er Choice
case "$Choice" in
"Y" | "y")
imgur_upload
;;
"N" | "n")
printf "\033c"
MenU
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"\"$Choice\" Is An Invalid Choice!!!"
echo -e ""
echo -e '\E[1;32;49m'"Correct Options To Choose Are From Y-N"
echo -e ""
echo -e '\E[1;32;49m'"To upload image to imgur, press \"Y\""
echo -e '\E[1;32;49m'"To go back the main menu, press \"N\""
echo -e '\E[1;32;49m'"Got it? It is not that hard you see"
echo -e ""
tput sgr0
read -r -s -p $'Press Any Key To Continue...\n' -n1
MenU
;;
esac
}

function MenU (){
printf "\033c"
type scrot >/dev/null 2>&1 || { printf "\033c"; echo -e ""; echo -e '\E[1;32;49m'"A required pmss dependency \"Scrot\" is not present."; echo -e '\e[1;32;49m'"\"Scrot\" is available for almost all linux distros."; echo -e '\e[1;32;49m'"Please install \"scrot\" using your package manager."; echo -e ""; tput sgr0; exit 1; }
DIR="${HOME}/Pictures/Screenshots"
if [ ! -d "${DIR}" ]; then mkdir --parents "${DIR}"; fi
client_id="af2f809b77dea2c"
echo -e '\E[1;32;49m'"** PMSS<>MENU *************************************************"
echo -e ""
echo -e ""
echo -e '\E[1;32;49m'"** Select One Of The Following Options"
echo -e ""
echo -e '\E[1;32;49m'"** Enter \"E\" To Take The Screenshot Of The Entire Screen"
echo -e '\E[1;32;49m'"** Enter \"W\" To Take The Screenshot Of Window In Focus"
echo -e '\E[1;32;49m'"** Enter \"A\" To Take The Screenshot Of Area Selected By Mouse"
echo -e '\E[1;32;49m'"** Enter \"Q\" To Exit"
echo -e ""
echo -e '\E[1;32;49m'"***************************************************************"
echo -e ""
tput sgr0
read -er Options
case "$Options" in
"E" | "e")
entire_area
;;
"W" | "w")
window_focus
;;
"A" | "a")
area_mouse
;;
"Q" | "q")
bye_bye
;;
*)
printf "\033c"
echo -e ""
echo -e '\E[1;32;49m'"\"$Options\" Is An Invalid Option!!!"
echo -e ""
echo -e '\E[1;32;49m'"Correct Options To Choose Are From E-W-A-Q"
echo -e ""
echo -e '\E[1;32;49m'"To Take The Screenshot Of The Entire Screen, Press \"E\" & Hit \"Enter\" Key"
echo -e '\E[1;32;49m'"To Take The Screenshot Of Window In Focus, Press \"W\" & Hit \"Enter\" Key"
echo -e '\E[1;32;49m'"To Take The Screenshot Of Area Selected By Mouse, Press \"A\" & Hit \"Enter\" Key"
echo -e '\E[1;32;49m'"To Exit From PMSS, Press \"Q\" & Hit \"Enter\" Key"
echo -e ""
tput sgr0
read -rsp $'Press Any Key To Return To PMSS MENU..\n' -n1
MenU
;;
esac
}
while :
do
MenU
done



Cheers!!!
You Can't Always Git What You Want

VastOne

I love it!

Awesome work!

Just one question, why have Firefox open the finished scrot after it is done?

I see the xdg-open "${NAME}" command so perhaps it is a setting issue on my end
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

It will also be included as yet another epic tool on VSIDO ISO's
VSIDO      VSIDO Change Blog    

    I dev VSIDO

Snap


hakerdefo

Quote from: VastOne on December 12, 2016, 02:48:50 AM
I love it!

Awesome work!

Just one question, why have Firefox open the finished scrot after it is done?

I see the xdg-open "${NAME}" command so perhaps it is a setting issue on my end

Hi there VastOne,
Running these commands in terminal will open two of the most common image types in Mirage instead of Firefox,

xdg-mime default mirage.desktop image/png

xdg-mime default mirage.desktop image/jpeg

You can use 'xdg-mime' command to determine file type,

xdg-mime query filetype example.pdf

Will get you,

application/pdf

And then you can change the xdg-open association for pdf like this,

xdg-mime default evince.desktop application/pdf

You can view the current default xdg-open application for a file type like this,

xdg-mime query default text/plain

Will print something like this,

medit.desktop

Cheers!!!
You Can't Always Git What You Want

hakerdefo

You Can't Always Git What You Want

hakerdefo

Quote from: VastOne on December 12, 2016, 02:49:18 AM
It will also be included as yet another epic tool on VSIDO ISO's

An honour!!!
Cheers!!!
You Can't Always Git What You Want

PackRat

#7
I tried all the options.

Capturing the desktop and selected area work. When I tried the "window in focus" option, there is an error -

scrot: invalid option -- 'u'

and the script finishes by taking a screenshot of the entire desktop. Taking a screenshot of the window in focus only isn't listed in the scrot man page. That an option with another app like feh?

the upload to imagur appears to work; need to remember to copy the link before returning to main menu.



Well done!!
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Quote from: hakerdefo on December 12, 2016, 07:17:18 AM
Quote from: VastOne on December 12, 2016, 02:48:50 AM
I love it!

Awesome work!

Just one question, why have Firefox open the finished scrot after it is done?

I see the xdg-open "${NAME}" command so perhaps it is a setting issue on my end

Hi there VastOne,
Running these commands in terminal will open two of the most common image types in Mirage instead of Firefox,

xdg-mime default mirage.desktop image/png

xdg-mime default mirage.desktop image/jpeg

You can use 'xdg-mime' command to determine file type,

xdg-mime query filetype example.pdf

Will get you,

application/pdf

And then you can change the xdg-open association for pdf like this,

xdg-mime default evince.desktop application/pdf

You can view the current default xdg-open application for a file type like this,

xdg-mime query default text/plain

Will print something like this,

medit.desktop

Cheers!!!

Great explanation and how to for anyone needing this.. I had already made the changes but wondered if there was a reason why Firefox was used

Now that it is changed, everything is functioning to my liking, and I will make the following changes to the default ISO:

xdg-mime default mirage.desktop image/png

xdg-mime default mirage.desktop image/jpeg
VSIDO      VSIDO Change Blog    

    I dev VSIDO

VastOne

Quote from: PackRat on December 12, 2016, 12:56:01 PM
I tried all the options.

Capturing the desktop and selected area work. When I tried the "window in focus" option, there is an error -

scrot: invalid option -- 'u'

and the script finishes by taking a screenshot of the entire desktop. Taking a screenshot of the window in focus only isn't listed in the scrot man page. That an option with another app like feh?


This is working fine for me here on VSIDO PackRat.. is it possible an app may be missing? wmctrl mayhap?
VSIDO      VSIDO Change Blog    

    I dev VSIDO

PackRat

No, xdotool and wmctrl are like the first two apps I add to any and all distros (why are they not default?)

It may be a difference in the way scrot is compiled for Void. If you try:

scrot -u

in a terminal, what is the result?

The maintainer at Void may not have enabled an option the Debian maintainer did - (better example, java is not enabled for LibreOffice in Void). There is also no "u" option listed in the manpage for scrot on my Void systems.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

VastOne

Quote from: PackRat on December 12, 2016, 04:53:48 PM
No, xdotool and wmctrl are like the first two apps I add to any and all distros (why are they not default?)

It may be a difference in the way scrot is compiled for Void. If you try:

scrot -u

in a terminal, what is the result?

The maintainer at Void may not have enabled an option the Debian maintainer did - (better example, java is not enabled for LibreOffice in Void). There is also no "u" option listed in the manpage for scrot on my Void systems.

xdotool and wmctrl  are defaults in a certain VSIDO distro..  :P  8)

scrot -u does do the focused window as it should for me and drops it in the directory with a filedate name
VSIDO      VSIDO Change Blog    

    I dev VSIDO

hakerdefo

#12
Quote from: VastOne on December 12, 2016, 02:48:50 AM
...
Now that it is changed, everything is functioning to my liking, and I will make the following changes to the default ISO:

xdg-mime default mirage.desktop image/png
xdg-mime default mirage.desktop image/jpeg

...

Edited Post

Hi VastOne,

Here is a better way to implement this in VSIDO ISO,

Make the following directory structure in user's home directory


~/.local/share/applications


And create 'mimeapps.list' file there,


~/.local/share/applications/mimeapps.list


And in the 'mimeapps.list' file we can add associations and we can also set default applications.

Here is an example 'mimeapps.list' file,


[Default Applications]
image/jpeg=mirage.desktop
image/png=mirage.desktop
application/pdf=evince.desktop

[Added Associations]
image/jpeg=mirage.desktop;
image/png=mirage.desktop;
application/pdf=evince.desktop;


We can add as many filetype associations we want and/or associate as many default applications as we want  in the 'mimeapps.list' file.

I think this can be easily implemented via "/etc/skel" in VSIDO ISO.

Cheers!!!
You Can't Always Git What You Want

hakerdefo

Quote from: PackRat on December 12, 2016, 12:56:01 PM
...
I tried all the options.

Capturing the desktop and selected area work. When I tried the "window in focus" option, there is an error -

scrot: invalid option -- 'u'

and the script finishes by taking a screenshot of the entire desktop. Taking a screenshot of the window in focus only isn't listed in the scrot man page. That an option with another app like feh?
...

Hi there PackRat,
The original version of Scrot doesn't have the "-u, --focused" option to capture currently focused window. I haven't used Void Linux so I can't say about its Scrot implementation but Slackware for sure doesn't have the "-u, --focused" option. Debian uses the patched version of the Scrot that has the "-u, --focused" option. I think Arch Linux also patches its implementation of Scrot with Debian's modifications. Here are the patches implemented by Debian if you are interested,

Debian-Scrot-Patches

Cheers!!!
You Can't Always Git What You Want

PackRat

Thanks; patch failed and I didn't want to mess with it.

Scrot is a simple binary so I downloaded the deb file from the Debian Sid packages. Extracted the files and copied scrot to /usr/local/bin/debscrot

Edited your script to use debscrot; script is hitting on all cylanders now.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo