Display Photos from OneDrive on your Windows Lock Screen

Published on 10th March 2024 in Development

I created a digital photo frame on my living room TV by filling my Windows lock screen with images from my personal photo archive (stored in OneDrive).

This post is about how I did this in such a way that I could curate the photos on an ongoing basis with minimal effort.

My New Media Center PC

After years of using a Google Chromecast to watch YouTube and TV I talked myself into buying a Geekom Mini PC instead as a media center.

Nowadays I pretty much only watch on-demand telly, YouTube, and live TV on major channels, all over the internet. My 2nd gen Chromecast doesn’t give the best experience for this any more; you can’t log into your YouTube account, remote control is ropey, and casting over Wi-Fi often fails.

By contrast, I reasoned, I could spend 250 quid, get an Intel i7 Windows machine and a wireless keyboard and not only would I get a smooth TV experience, I’d also be able to play a whole host of games* which – having not owned a Windows PC for about 14 years – was a proposition overall that I think was worth that money!

Digital Photo Frame

One thing I’d always planned to do with the Chromecast was to make it so that my favourite photos showed on the idle screen.

By default on the Chromecast you see a selection of random (very nice) images from Google Photos. “However”, I thought, “I have nice photos of my own!”

By default I dump all my photos into Microsoft OneDrive to keep them available wherever I am and backed-up in the cloud. Accumulated over twenty years, amongst tens of thousands of average-joe quality digital photos, are some that I really quite like. Once in a while it would be nice to actually look at them!

My plan was to “sync” the photos I wanted from OneDrive to a Google photos album which would allow me to show them on the Chromecast idle screen. However, having got the media center PC, I switched focus to getting the photos to display on the Windows Lock Screen instead.

The Vision

OneDrive obviously integrates with Windows but the standard setup did not quite do what I wanted. I wanted a curated set of photos shown on the lock screen and the best OneDrive offered was to sync whole folders of photos to local devices. The way my photos are organised I’d usually only want one or two pictures from a folder to display on the lock screen.

So I planned to write my own script to sync just the pictures I wanted to the media center. The plan was:

  1. Set up the PC to display images from a local folder on the lock screen.
  2. Set up the PC to go to the lock screen when idle e.g. 5 minutes after finishing watching TV.
  3. Write a script to selectively download photos from OneDrive to the lock screen folder. I would do this by tagging the photos and only downloading the ones which had a specific tag. I chose a tag that wouldn’t naturally appear on any photos: “slideshowsync”.
  4. Run the script on a schedule to download the tagged files on a regular basis.
  5. Go and tag all the photos I wanted on the lock screen with the tag.

In this way I would have just the photos I wanted stored on the PC and at any time I could tag or untag the photos in OneDrive to control what was displayed on the lock screen. No additional curation or duplication of the files would be needed.

I Thought Personalising Windows Was Easy!

I fully expected the simplest part of this to be to get Windows 11 to display random photos on the lock screen but I ended up spending ages tuning this to be how I wanted.

My aim was simply to have a static random image which changed every few minutes with no cheesy transitions. By default however the Windows 11 “lock screen slideshow” mode changes the photo every 5 seconds or so with a nasty harsh transition between images and the uber-distracting Ken Burns effect running perpetually 😡.

Beyond this, getting the PC to go into the lock screen mode and stay there without turning off the display or going to sleep was mindblowingly difficult. I felt as though conflicting settings baked into Windows over many years made this less than simple and hard to test.

In the end here’s how I configured everything…

Dynamic Theme
Screenshot showing the configuration of the Dynamic Theme app. The options to recursively navigate image folders and display photos at random are selected. Image fit is set to fill. Images will change every 15 minutes.
To get away from the cheapness of the Windows native experience I found a neat app called Dynamic Theme which can display random images on the lock screen from a source folder with no transitions or effects. Simplicity, eh? 🙄 I would have preferred a shorter transition time (maybe 5 minutes) between images and am yet to find a way of adjusting this, but everything else behaves as I’d like it to.
Windows Lock Screen Settings
Screenshot of the native windows lock screen personalisation settings. The option to show the lock screen when the PC is idle is ticked.
Dynamic Theme doesn’t control all aspects of the lock screen experience. I set the following setting to true: When my PC is inactive, show the lock screen instead of turning off the screen.
Windows Power Settings
Windows power settings showing that the display off timeout is 5 minutes and the computer will sleep after two hours.
The “show the lock screen when inactive” setting in the previous step means that Turn off the display now means show the lock screen after 5 minutes and DON’T turn off the display. Intuitive! Setting the sleep timer to two hours means that the PC stops emitting a display signal after a long idle. In turn my TV would go into standby; I have some level of consciousness about my energy consumption.

However there was a problem: the computer would hit the lock screen after 5 minutes, then shortly after the display would turn off, meaning you wouldn’t get the effect of the PC behaving as a digital photo frame.

I could have set Turn display off  to “Never” but then you’d only be able to reach the lock screen by manually locking the PC. What to do?

There was one final setting I needed which is hidden by default. It’s called Console lock display off timeout and you need to enable it in the registry before it can be changed.

Screenshot showing windows power settings. A setting called Console lock display off timeoutout is set to 120 minutes.
This defines how long the lock screen should display before the PC switches off the display. After all, you did just set the setting to make the actual “display off” setting send you to the lock screen instead! The default value is 60 seconds which is why the lock screen only stays on for a short time regardless of the “Turn off the display” settings in Power Options. I set the Console Lock Timeout in alignment with my sleep setting (120 minutes).

I think it’s worth recapping the settings balancing act as I found it pretty confusing…

If you were happy manually-locking the PC, or using the “walk away” lock feature, maybe you could set the display timeout to “Never” which would apparently negate the need to set the Console lock timeout! 🤷🏻‍♂️

PowerShell Script to Sync Selected OneDrive Photos by Tag (The clever bit)

What I thought would need considered effort is was the script to fetch the photos from OneDrive. This almost turned out to be the easy part!

My first thought was to learn how to build something in .NET but I quickly realised PowerShell would be a more natural choice. The script would be largely procedural and PowerShell has a mature ecosystem including a very useful OneDrive library which would cut out a lot of HTTP boilerplate.

All the script ultimately does is retrieve all the search results associated with the arbitrary tag I set on the photos and downloads those files locally. Subsequent runs work out the delta of the search results and skip or delete existing files as necessary.

Screenshot of a black and white windows cmd terminal showing example output for the onedrive search term sync script.
Output from the script as it runs on the local PC.

Once I had this all working, I put it on the classic Windows Task Scheduler to be run each time I log on to the PC.

powershell .\sync.ps1 -WindowStyle Hidden

Screenshot of the Windows task scheduler set up to run the OneDrive sync script at user logon.

The Final Results

Everything now works pretty much as I’d envisioned. I can tag photos in OneDrive, and next time I log on to the media centre, new photos are available for the lock screen which randomly displays them and changes elegantly every 15 minutes.

Screenshot of the tagging interface in Microsoft OneDrive with my arbitrary slideshowsync tag applied to a photo.
Applying the arbitrary slideshowsync tag to photos in OneDrive.

The PC won’t go idle whilst watching media and as long as we exit fullscreen when we’re finished the PC manages itself into lock mode and we can enjoy an ambient photo experience on our living room TV.

Picture of my TV showing a photo synced using the script
 

A couple of small followups I haven’t yet got around to. (a) I’d like to work out how to display HEIC photos as many of my photos are in this native Apple format but Dynamic Theme doesn’t seem to pick them up. (b) I’d like to have the script run invisibly whereas, at the moment, I see the shell window pop up for a short time (increasing with the number of synced files) upon logon. I just need to get some permissions settings right to do this, I think!