Automate Saving Windows Spotlight Images by Python

Nazmul Ahsan
Nov 9 · 3 min read
Windows 10 lock screen

Windows 10 has a great feature called Windows spotlight that automatically updates your lock screen background with amazing photos. Unfortunately, there is no built-in way to put them in your desktop background too. And the image files are saved in the deepest part of the jungle of windows file system. So it’s pretty hard to find where they are. Manually copying them to your preferred directory is possible, but you have to copy the files and rename them to add the .jpeg extension in order to make them work with any photo opening app. I guess you get the idea that practically that is very hectic. That’s why, as a fun project, I automated the process with python.

Concept of the program

Before we jump into code, let’s see what we want the program to do. Windows saves the image file in your computer in the following directory,


There you will find many files without any file extension. The larger files are the images that we want. We can assume the spotlight images are more than 400 KB. Assuming that, we want to copy those file to our desired directory, rename the file whatever we want, with the file extension .jpeg added by us manually so that we can open the images by double clicking on them and use them as desktop wallpaper and whatever we want.

Jump to code

We want to automate this copying and renaming task. If you are not a programmer and just want a program that will do this for you, you can download my program from my drive link here.

For the programmer, let’s dive in.

# Import libraries
import os
from getpass import getuser
from shutil import copyfile

As you see, the directory contains the name of the user. So, before we can hard code the directory in our program, we need to get the user name from the OS.

# Getting the username
user = getuser()

Now we are ready to save the source directory of the files in a variable name ‘src’ (whatever you wish).

# setting the directory of the spotlight images                       src='C:/Users/'+user+'/AppData/Local/Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets'

Now, set the destination where we want to save the files.

dist = 'C:/Users/'+user+'/Desktop/SpotLight Wallpaper'                           if not os.path.exists(dist):
os.mkdir(dist) # Creates the folder if it doesn't exist

I saved the files in the desktop. You can save it in any directory you want.

Now, we want to list the files that are in the src directory and more than 200 KB in size (this is just an assumption, you can try different file sizes if you are not happy with it).

# Creating an empty list
curr_img_list = []
# Listing all the files in the src directory
file_list = os.listdir(src)
# Taking the file names that are more than 200 KB
for file in file_list:
if os.path.getsize(src+'/'+file)>204800:

We are almost there. Now we need to run a block of code that will take every file in the ‘curr_img_list’ and rename them in the new directory with proper file extension.

i = 1
# Running a for loop
for img in current_img_list:
old_dir = src+'/'+img # directory of the img
new_dir = dist+'/img_'+str(i)+'.jpeg' # new directory
copyfile(old_dir, new_dir) # copying from old to new

That’s it! All the available images will now appear in the destination folder.

Final Touch

The code is complete and good enough to extract the current images. But you will notice, if you keep running it again and again, it will keep replacing the previously extracted images because of the same name. So, if new images come, and you don’t move your previously extracted images from the new directory, the newer files will replace the older ones. Hence you will lose them. You can move them in separate folder after extracting, or change the directory inside the code before running it again. Or, you can fine tune this code, so that this thing doesn’t happen at all. That can be done very easily. I encourage you to solve that problem on your own. And if you want to see my solution, I have my complete code in my github repo here. But before seeing my code, try it yourself.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade