Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. param(
  2. # The folder containing the images
  3. [Parameter()][string]$imgPath = $env:imgPath,
  4. [Parameter()][string]$bgiPath = $env:bgiPath
  5. )
  6. if ([string]::IsNullOrEmpty($imgPath) -or [string]::IsNullOrEmpty($bgiPath)) {
  7. throw "You need to set imgPath and bgiPath environment variables or pass them in."
  8. }
  9.  
  10. #region function definitions
  11. function Set-WallPaper($value) {
  12. Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name WallPaper -Value $value
  13. Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name WallpaperStyle -Value 10
  14. Set-ItemProperty -Path 'HKCU:\Control Panel\Desktop\' -Name TileWallpaper -Value 0
  15. RUNDLL32.EXE USER32.DLL,UpdatePerUserSystemParameters 1, True
  16. }
  17. #endregion
  18.  
  19. # get image list
  20. $imgList = Get-ChildItem $imgPath |
  21. Where-Object {('.jpg','.bmp','.png').Contains($_.Extension)} |
  22. Sort-Object { [regex]::Replace($_, '\d+', { $args[0].Value.PadLeft(20) }) } # natual sort
  23. if ($imgList.Length -eq 0) { throw ('No image found under ' + $imgPath) }
  24.  
  25. # select a wallpaper based on date
  26. [System.IO.FileSystemInfo]$img = $null
  27. $imgIdx = 0
  28. $now = Get-Date
  29. if ($imgList.Length -gt 12) {
  30. # more than 12 images found (distributed over a year)
  31. $imgIdx = ($now.DayOfYear - 1) % $imgList.Length
  32. }
  33. else {
  34. # less than 12 images (one per month)
  35. $imgIdx = ($now.Month - 1) % $imgList.Length
  36. }
  37. $img = $imgList[$imgIdx]
  38.  
  39.  
  40. # apply configuration
  41. Set-WallPaper $img.FullName
  42. Start-Process -FilePath 'bginfo.exe' -ArgumentList 'config.bgi /timer:00' -WorkingDirectory $bgiPath
  43. Write-Host ('Wallpaper set to ' + $img.FullName)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement