powershell 下载并设置为桌面壁纸的 jio 本, 大概只支持 Windows 10, Windows 7 可能需要升级 Powershell, 异常处理什么的不存在的...
另存成 .ps1 文件, 右键运行即可, 可能需要修改 ps 执行策略:
Write-Host -ForegroundColor Red "下载 bing 每日壁纸"
# set save directory
$saveDir = Join-Path -Path ([Environment]::GetFolderPath('myPictures')) -ChildPath '必应壁纸'
New-Item -ItemType Directory -Path $saveDir -ErrorAction Ignore
# fetch URL
$bingHost = "
https://www.bing.com"
$bingImageApi = $bingHost + "/HPImageArchive.aspx?format=js&idx=0&n=1&mkt=zh-CN"
# invoke web request
$bingImage = (irm -UserAgent ([Microsoft.PowerShell.Commands.PSUserAgent]::InternetExplorer) -Uri $bingImageApi).images[0]
# gather image infomation
$imageCopyright = $bingImage.copyright
if ($bingImage.url -cmatch '^https*://') {
$imageUrl = $bingImage.url
} else {
$imageUrl = $bingHost + $bingImage.url
}
# get local file name
if (($bingImage.url) -match 'id=OHR\.(?<imageName>.+?)&.*') {
$saveName = $Matches.imageName
} else {
$saveName = 'Bing-' + $(Get-Date -UFormat '%y%m%d') + '.jpg'
}
# Download
$savePath = (Join-Path -Path $saveDir -ChildPath $saveName)
Write-Host -ForegroundColor Green $imageUrl, '->', $savePath
irm -Uri $imageUrl -OutFile $savePath
# set Windows desktop wallpaper
# Win32 API
$win32ApiSignature = @"
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern bool SystemParametersInfo(uint uiAction, uint uiParam, string pvParam, uint fWinIni);
"@
$User32 = Add-Type -MemberDefinition $win32ApiSignature -Name 'User32' -Namespace 'Win32' -PassThru
# Set wallpaper
$User32::SystemParametersInfo(0x0014, 0, $savePath, 0x0001)
# 暂停, 可以注释掉
Read-Host
目测 v2 的排版会跪, 幸好不是 python