"Whenever you can, share. You never know who all will be able to see far away standing upon your shoulders!"
I write mainly on topics related to science and technology.
Sometimes, I create tools and animation.
June 21, 2021
Author - manisar
Small and insignificant as it may seem, the transition from PrintScreen
to Win+Shift+S
has been really helpful for technical and casual Windows users alike. But there is something that had been of a bit of a bother for me.
After you have captured a screenshot, you get a picture in the clipboard. If you are using a photo editor (such as Paint or paint.net), or any client app capable of grabbing this picture from clipboard (such as WhatsApp Web) you can use it for working with the screenshot. But what if you just wanted the picture as a file so that you can use it in any way you wanted, e.g. for uploading through a browser file upload, or simply using it later for something?
Same for images copied into clipboard from other apps such as Word, browser etc.
For long I was using Paint to capture the image after hitting Win+Shift+S
, or after copying them from other apps, and then using the save feature in Paint. A bit of a hassle.
Finally I came up with the following using Python. So this is my workflow now:
Win+Shift+S
, or copy image from another app.tempfile.jpg
), and immediately takes Windows to file rename mode for this file. All I have to do is type the new desired name for this file.Thus, with these three sets of keystrokes, I get a .jpg file at my disposal.
Win+Shift+S
for taking the screenshot, or, right clicking in other apps and selecting 'Copy Image'Ctrl+Alt+F
for opening a designated folder (optional)Ctrl+Alt+I
for saving the image as a file and letting me rename the file immediatelyThe shortcuts keys F
and I
are what I chose, you can choose any another key.
I'll now explain all the steps needed for setting up this mechanism.
The following is for Windows users. Linux and Mac users will have to tweak the scripts.
.py
files, we'll also need to be able to run .pyw
files. So create a temporary .pyw
file anywhere, right click on and change Opens with to: C:\Program Files (x86)\Python37-32\pythonw.exe
.pip
which automatically comes with Python 2 >=2.7.9 or Python 3 >=3.4.curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
regedit
.Computer\HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command
(Default)
key to "C:\Program Files (x86)\Python37-32\python.exe" "%1" "%*"
Computer\HKEY_CLASSES_ROOT\Applications\pythonw.exe\shell\open\command
, make the default key "C:\Program Files (x86)\Python37-32\pythonw.exe" "%1"
:python.exe
and pythonw.exe
may be different for you, don't change them, just add the arguments in the end. Remember to include the quotes..pyw
(say Script1.pyw
)..pyw
extension is for running this script without invoking a command line window which we don't need for this functionality.Script1.pyw
.Shortcut
tab, enter a key of your choice for Shortcut key
(say F
), and press Ok.Ctrl+Alt+F
from anywhere will open the folder D:\Images
.We need a few packages installed on top of your system level Python.
Run the following commands in Windows cmd.
pip show PIL
. If not, install pillow using pip install pillow
.pip install pywin32
pip install pyautogui
Now, copy and paste the code given below to any file on your computer ending with .pyw
(say Script2.pyw
). Change the startingPath
to the path of the folder you used in Script1.pyw
.
On running this script, if it finds a Windows folder in foreground, it saves the image there, otherwise it will save the image file at startingPath
.
Script2.pyw
.Shortcut
tab, enter a key of your choice for Shortcut key
(say I
), and press Ok.Ctrl+Alt+I
from anywhere will grab the image (if there is any) from clipboard and save it in the foreground folder or D:\Images
. Right after saving the file, you will be taken to the file rename mode - simply enter the <new_filename>, you will have <new_filename>.jpg
.Note: You can change the image quality etc. by modifying the line im.save(fullPath,'JPEG', subsampling=0, quality=95)
in the second script.
Happy screen capturing!
Return to Coding and Development - Reference and Tools