Created
May 15, 2016 11:18
-
-
Save Workshop2/a318e64078f8122eab717bbd896e2657 to your computer and use it in GitHub Desktop.
Set a wallpaper based on date (Bing wallpapers)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$targetDate = (Get-Date).ToString("yyyyMM01") | |
Write-Host "targetDate: $targetDate" | |
$wallpaperOutput = "$env:USERPROFILE\Pictures\wallpaper.jpg" | |
Write-Output "Downloading data feed..." | |
$wallpaperData = "http://www.bing.com/gallery/home/browsedata?z=0" | |
$json = (Invoke-WebRequest $wallpaperData -UseBasicParsing).Content | |
Write-Output "Parsing JSON..." | |
$imageNames = ("{" + [regex]::match($json, '\"imageNames\"\:(.*?)\]').Groups[0].Value + "}" | ConvertFrom-Json).imageNames | |
$dates = ("{" + [regex]::match($json, '\"dates\"\:.*?\]').Groups[0].Value + "}" | ConvertFrom-Json).dates | |
Write-Output "Building link table..." | |
$Table = @{} | |
for ($i = 0; $i -le 30; $i++) { | |
$Table.Add($dates[$i].ToString(), $imageNames[$i]) | |
} | |
$wallpaperUrl = "http://az608707.vo.msecnd.net/files/" + $Table.$targetDate + "_1920x1080.jpg" | |
Write-Output "Generated wallpaper URL: $wallpaperUrl" | |
Write-Output "Downloading wallpaper..." | |
Invoke-WebRequest $wallpaperUrl -OutFile $wallpaperOutput -UseBasicParsing | |
Write-Output "Setting registry key...HKCU:\Control Panel\Desktop\ -> wallpaper -> $wallpaperOutput" | |
Set-ItemProperty -path 'HKCU:\Control Panel\Desktop\' -name wallpaper -value $wallpaperOutput -force | |
rundll32.exe user32.dll, UpdatePerUserSystemParameters | |
rundll32.exe user32.dll, UpdatePerUserSystemParameters | |
rundll32.exe user32.dll, UpdatePerUserSystemParameters |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment