Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- param(
- # The folder containing the images
- [Parameter()][string]$imgPath = $env:imgPath,
- [Parameter()][string]$bgiPath = $env:bgiPath
- )
- if ([string]::IsNullOrEmpty($imgPath) -or [string]::IsNullOrEmpty($bgiPath)) {
- throw "You need to set imgPath and bgiPath environment variables or pass them in."
- }
- #region function definitions
- function Set-WallPaper($value) {
- Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name WallPaper -Value $value
- Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name WallpaperStyle -Value 10
- Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name TileWallpaper -Value 0
- RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
- }
- #endregion
- # get image list
- $imgList = Get-ChildItem $imgPath |
- Where-Object {('.jpg','.bmp','.png').Contains($_.Extension)} |
- Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } # natual sort
- if ($imgList.Length -eq 0) { throw ('No image found under ' + $imgPath) }
- # select a wallpaper based on date
- [System.IO.FileSystemInfo]$img = $null
- $imgIdx = 0
- $now = Get-Date
- if ($imgList.Length -gt 12) {
- # more than 12 images found (distributed over a year)
- $imgIdx = ($now.DayOfYear - 1) % $imgList.Length
- }
- else {
- # less than 12 images (one per month)
- $imgIdx = ($now.Month - 1) % $imgList.Length
- }
- $img = $imgList[$imgIdx]
- # apply configuration
- Set-WallPaper $img.FullName
- Start-Process -FilePath 'bginfo.exe' -ArgumentList 'config.bgi /timer:00' -WorkingDirectory $bgiPath
- Write-Host ('Wallpaper set to ' + $img.FullName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement