save your favorite windows spotlight wallpapers/lock screens

sudheer naidu
3 min readAug 18, 2021

You’ve probably been there where you see a great picture on your windows lock screen and wanted to save it. This is only if you have enabled windows spotlight . If you haven’t.. what are you doing? seriously.

you are not using Windows spotlight? source:https://tenor.com/

I have been in that situation too. Not just once but probably once in every few weeks/months. And every time, I used to google to find out where those pictures are, and rename them to .jpg or view them in paint program. Yeah, the tedious and boring process.

me when I like a spotlight image and go on a hunt to find it. source: https://giphy.com/

So…. I thought why not simplify the process with few lines of code. Again as a normal human being, I googled. I found some scripts which will rename all the wallpapers to jpg. I don’t want all the images to be copied(again who would manually delete the unwanted ones?), I only want to save the ones I loved. Also , there are application icons stored in the same folder. I wouldn’t want them.

how I defend my googling habit. source:https://tenor.com/

So, I chose to write my own script.

The code

script to show all the spotlight images available and to save the images you want in jpg format.

Lets walk through the lines.

Import some libraries. os and glob to deal with files and directories. PIL to deal with images.

import os
import glob
from PIL import Image

Inputs are explained above in the docstring of the function. you would like to change the default value of user

The spotlight images are stored at “C:\Users\{user_name}\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets”

so, if user doesn’t give a path to write the images that he wants to save, we will by default write to the folder which contains spotlight images.

outpath = outpath or r"C:\Users\{}\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets".format(user) #write images here

we will then iterate through the images using the following line. glob.glob lists files which match the given pattern

for x in glob.glob(r"C:\Users\{}\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*".format(user)):

to avoid application icons present in the same folder (which are generally small in size), we would restrict the files which are less than some kilobytes in size(by default 100 Kb) and show the others

if os.path.getsize(x) > size_in_kb * 1024:

and then we would load the image and show it.

im = Image.open(x)
im.show(title=x)

and then take the input. If we like it and want to save it, type something. else just press enter. we could also give the name to save the image under (space seperated)

if inp:
if len(inp.split(" ")) > 1: # if inp is "y custom_name", image would be saved as custom_name.jpg else by default name
filename = inp.split(" ")[-1] # without any extension
else:
filename = x
im.save(os.path.join(outpath, filename + ".jpg"))

that’s it. We would get our fav images saved to some folder without doing a lot of manual work.

cheers. source:https://tenor.com/

Please clap or follow if you feel like this story deserves one.

--

--