Guide for LLM agents (Claude Code, Cursor, Copilot, etc.) working on this repository.
A PowerShell tool for Windows that sets James Webb Space Telescope photos as the desktop wallpaper, across one or more monitors. No external dependencies, no build step, no API key. Everything runs with the PowerShell included in Windows 10/11.
The project is deliberately minimal: two PowerShell scripts.
Entry points (parameters): -GUI opens the chooser window; -Monitor <n> changes a single monitor (0-based index); no arguments changes all monitors.
Flow and key functions:
$dwCode— inline C# definition of the COM interfaceIDesktopWallpaper(GUIDB92B56A9-...) and the static wrapper classDW.⚠️ The method order in the interface must exactly match the COM vtable — do not reorder them. Loaded at runtime withAdd-Type.Get-EsawebbPool— scrapesesawebb.org: downloads the category pages and extracts image ids via the regexhref="/images/([\w-]+)/", deduplicating and skipping non-image entries (archive,search, etc.).Get-CommonsPool/Get-CommonsThumbUrl— Wikimedia Commons fallback via theapi.phpAPI.Initialize-Pool— builds the pool only once: uses esawebb if it returns ≥10 images, otherwise Commons. State stored in$script:pool/$script:poolSource.Get-PreparedImage— downloads an image, resizes it withSystem.Drawingif the longest side exceeds$maxDim(default 3840 px), saves it as JPEG.Set-OneMonitor— picks a not-yet-used image, prepares it and sets it on the monitor viaDW::Set. Tries up to 6 candidates before giving up.Invoke-Switch— orchestrator: initializes the pool, loops over the monitor indices, sets the "Fit" position (DWPOS_FIT = 3) at the end.Show-Chooser— Windows Forms GUI with radio buttons (All / individual monitors) and a "Change" button.
Creates a "JWST Wallpapers" .lnk shortcut on the desktop (via the WScript.Shell COM object) that launches Set-SpaceWallpapers.ps1 -GUI with -ExecutionPolicy Bypass. Uses $PSScriptRoot to stay portable: it works from any folder.
- Language: comments, logs and the GUI are in English. Keep this convention.
- Verb-Noun: functions follow the standard PowerShell naming (
Get-,Set-,Invoke-,Initialize-,Show-). - Portability: do not hardcode absolute paths. Use
$PSScriptRoot(or the$MyInvocationfallback) as the base; everything is relative to the script folder. - Logging: use the
Write-Logfunction for every meaningful event; it writes tonasa-wallpaper.logand to stdout. - No external dependencies: PowerShell + system .NET assemblies only (
System.Drawing,System.Windows.Forms). Do not introduce modules to install or API keys.
Defined in .gitignore — do not commit them:
images/— wallpapers downloaded at runtime (they regenerate by themselves).*.log— execution logs.esawebb-example.jpg— example image too heavy (~10 MB).
There are no automated tests. Manual verification on Windows with at least one monitor:
# Quick test without GUI: change monitor 0
.\Set-SpaceWallpapers.ps1 -Monitor 0
# Check the outcome in nasa-wallpaper.logThe script requires real Windows (the IDesktopWallpaper COM API and System.Windows.Forms): it does not run on Linux/macOS or in headless environments.
- The
esawebb.orgscraping depends on the site's HTML structure: if the site changes, the regex inGet-EsawebbPoolmay break → in that case the Commons fallback kicks in. - Be respectful of the source sites: generous timeouts and a single
UserAgent. Do not increase the request rate. - Images must never be redistributed in the repo (licensing matter): they are only downloaded by the user at runtime. See the credits in the README.