Skip to content

Instantly share code, notes, and snippets.

@jkerhin
Created October 6, 2024 16:37
Show Gist options
  • Select an option

  • Save jkerhin/4b630a643df46d9df8042d965b268706 to your computer and use it in GitHub Desktop.

Select an option

Save jkerhin/4b630a643df46d9df8042d965b268706 to your computer and use it in GitHub Desktop.
Copy Windows 10 Locksceen photos to a local directory
#!/usr/bin/env python3
"""Copy Windows 10 lockscreens to a local directory
Uses heuristics to avoid copying other assets stored in the same directory. May be
imperfect, this has only been tested on two systems.
Big thanks to "CharlieRB" on SuperUser; without their answer I never would have figured
this out: https://superuser.com/a/1126475
"""
import argparse
import os
from pathlib import Path
def copy_lockscreens(out_dir: Path):
lockscreen_pth = (
Path(os.getenv("LOCALAPPDATA"))
/ "Packages/Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy/LocalState/Assets"
)
for pth in lockscreen_pth.glob("*"):
raw_bytes = pth.read_bytes()
if raw_bytes.startswith(b"\x89PNG"):
# All lockscreens are JPG, skip PNGs
continue
if len(raw_bytes) < 250_000:
# All lockscreens I've seen are >250k
continue
out_pth = out_dir / f"{pth.name}.jpg"
out_pth.write_bytes(raw_bytes)
def main():
parser = argparse.ArgumentParser(
description="Copies Windows 10 lockscreen images to a specified directory",
)
parser.add_argument(
"out_dir",
nargs="?",
type=Path,
default=".",
help="Directory lockscreens will be written to. Default: '%(default)s'",
)
out_dir = parser.parse_args().out_dir
if not out_dir.is_dir():
raise NotADirectoryError(f"Output directory {out_dir} is not a vaild directory")
copy_lockscreens(out_dir=out_dir)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment