I developed a PowerShell script a while back to scrape the latest wallpaper from the MTG website and set it as my desktop background. I finally got around to updating it today since it hadn’t worked for a while. My background changed to Frodo and I disabled the script.

If you want that though, here you go:

Function Set-WallPaper {
 
<#
 
    .SYNOPSIS
    Applies a specified wallpaper to the current user's desktop
    
    .PARAMETER Image
    Provide the exact path to the image
 
    .PARAMETER Style
    Provide wallpaper style (Example: Fill, Fit, Stretch, Tile, Center, or Span)
  
    .EXAMPLE
    Set-WallPaper -Image "C:\Wallpaper\Default.jpg"
    Set-WallPaper -Image "C:\Wallpaper\Background.jpg" -Style Fit

    https://www.joseespitia.com/2017/09/15/set-wallpaper-powershell-function/
  
#>
 
param (
    [parameter(Mandatory=$True)]
    # Provide path to image
    [string]$Image,
    # Provide wallpaper style that you would like applied
    [parameter(Mandatory=$False)]
    [ValidateSet('Fill', 'Fit', 'Stretch', 'Tile', 'Center', 'Span')]
    [string]$Style
)
 
$WallpaperStyle = Switch ($Style) {
  
    "Fill" {"10"}
    "Fit" {"6"}
    "Stretch" {"2"}
    "Tile" {"0"}
    "Center" {"0"}
    "Span" {"22"}
  
}
 
If($Style -eq "Tile") {
 
    New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
    New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 1 -Force
 
}
Else {
 
    New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name WallpaperStyle -PropertyType String -Value $WallpaperStyle -Force
    New-ItemProperty -Path "HKCU:\Control Panel\Desktop" -Name TileWallpaper -PropertyType String -Value 0 -Force
 
}
 
Add-Type -TypeDefinition @" 
using System; 
using System.Runtime.InteropServices;
  
public class Params
{ 
    [DllImport("User32.dll",CharSet=CharSet.Unicode)] 
    public static extern int SystemParametersInfo (Int32 uAction, 
                                                   Int32 uParam, 
                                                   String lpvParam, 
                                                   Int32 fuWinIni);
}
"@ 
  
    $SPI_SETDESKWALLPAPER = 0x0014
    $UpdateIniFile = 0x01
    $SendChangeEvent = 0x02
  
    $fWinIni = $UpdateIniFile -bor $SendChangeEvent
  
    $ret = [Params]::SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, $Image, $fWinIni)
}

$result = Invoke-RestMethod 'https://magic.wizards.com/en/news#wallpapers'
$result -match "//(.*?)2560(.*?).png"
$wallpaper = $Matches[0]
$picfolder = [Environment]::GetFolderPath([Environment+SpecialFolder]::MyPictures)
$filename = $wallpaper.Split('/')[-1]
$foldername = "MTG Wallpapers"
$savefile = "$picfolder\$foldername\$filename"

If (-not (Test-Path "$picfolder\$foldername")) {
    New-Item -Path $picfolder -name $foldername -ItemType "directory"
}

If (-not (Test-Path $savefile)) {
        Invoke-WebRequest http:$wallpaper -OutFile $savefile
        Set-WallPaper -Image $savefile -Style Fill
}

Paste that into PowerShell ISE and run it and see if it works. If you like it, save it and put a shortcut in your startup folder. By default it downloads the 2560x1600 version but if you want a different one just replace the 2560 in the line $result -match “//(.?)2560(.?).png” with 1920 or 1280. It saves images in a folder under your Pictures folder called MTG Wallpapers. You can change that too if you want by editing the $picfolder and $foldername lines.

Have fun.

  • LovesTha
    link
    fedilink
    English
    arrow-up
    2
    ·
    1 year ago

    Nice script, pity they don’t have any serious resolutions (3440*1440 is my jam)