-
-
Save sbrown7792/4cac85a6d647a8c38e337a88628a4e1e to your computer and use it in GitHub Desktop.
Windows Powershell Script to download the latest image from the GOES-16 satellite, resize to desktop resolution and then set as the desktop background.
This file contains hidden or 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
# | |
# GOES-16 (East) CONUS Downloader | |
# -- Forked from Himawari-8 Downloader by Michael Pote: https://gist.github.com/MichaelPote/92fa6e65eacf26219022 | |
# | |
# | |
# This script will scrape the latest image from the GOES East satellite which is saved in My Pictures\GOES\, | |
# resized to fit your resolution (so no harsh aliasing) and then set as the desktop background. | |
# ***** MAKE SURE YOU SET YOUR RESOLUTION IN THIS SCRIPT **** (line 60-ish) | |
# | |
# https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/latest.jpg | |
# | |
# Call this script every (5-10?) minutes using taskschd.msc so your wallpaper keeps up to date | |
# https://blog.netwrix.com/2018/07/03/how-to-automate-powershell-scripts-with-task-scheduler/ | |
# Make sure to select "Run whether user is logged on or not" or else a window will pop-up whenever the script is run | |
# | |
#Create the folder My Pictures\Goes\ if it doesnt exist | |
$outpath = [Environment]::GetFolderPath("MyPictures") + "\GOES\" | |
if(!(Test-Path -Path $outpath )) | |
{ | |
[void](New-Item -ItemType directory -Path $outpath) | |
} | |
#The filename that will be saved: | |
$outfile = "latest.jpg" | |
#choose which size you want to download, depending on your monitor resolution | |
#huge | |
$url = "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/5000x3000.jpg" | |
#big | |
#$url = "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/2500x1500.jpg" | |
#medium | |
#$url = "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/1250x750.jpg" | |
#tiny | |
#$url = "https://cdn.star.nesdis.noaa.gov/GOES16/ABI/CONUS/GEOCOLOR/625x375.jpg" | |
Write-Output "Downloading $url to $outpath$outfile" | |
$wc = New-Object System.Net.WebClient | |
$wc.DownloadFile($url, $outpath + $outfile) | |
#resize code taken and tweaked from: https://benoitpatra.com/2014/09/14/resize-image-and-preserve-ratio-with-powershell/ | |
$imageSource = $outpath + $outfile | |
$imageTarget = $outpath + $outfile + "-resized.jpg" | |
$quality = 100 | |
if (!(Test-Path $imageSource)){throw( "Cannot find the source image")} | |
if(!([System.IO.Path]::IsPathRooted($imageSource))){throw("please enter a full path for your source path")} | |
if(!([System.IO.Path]::IsPathRooted($imageTarget))){throw("please enter a full path for your target path")} | |
if ($quality -lt 0 -or $quality -gt 100){throw( "quality must be between 0 and 100.")} | |
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | |
$bmp = [System.Drawing.Image]::FromFile($imageSource) | |
#hardcoded canvas size... ####### SET YOUR DESKTOP RESOLUTION HERE ####### | |
# (I'm sure there's a way to do this programmatically, I'll leave that for the next forker) | |
$canvasWidth = 2560 | |
$canvasHeight = 1440 | |
#Encoder parameter for image quality | |
$myEncoder = [System.Drawing.Imaging.Encoder]::Quality | |
$encoderParams = New-Object System.Drawing.Imaging.EncoderParameters(1) | |
$encoderParams.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter($myEncoder, $quality) | |
# get codec | |
$myImageCodecInfo = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders()|where {$_.MimeType -eq 'image/jpeg'} | |
#compute the final ratio to use | |
$ratioX = $canvasWidth / $bmp.Width; | |
$ratioY = $canvasHeight / $bmp.Height; | |
$ratio = $ratioY | |
#change 'ge' to 'le' if you don't want to miss any part of the image | |
#this means that there may be black bars around your image | |
#keep at 'ge' if you want the image to fill the entire screen, | |
#at the expense of a little missing image around the edge | |
if($ratioX -ge $ratioY){ | |
$ratio = $ratioX | |
} | |
#create resized bitmap | |
$newWidth = [int] ($bmp.Width*$ratio) | |
$newHeight = [int] ($bmp.Height*$ratio) | |
$bmpResized = New-Object System.Drawing.Bitmap($newWidth, $newHeight) | |
$graph = [System.Drawing.Graphics]::FromImage($bmpResized) | |
$graph.Clear([System.Drawing.Color]::White) | |
$graph.DrawImage($bmp,0,0 , $newWidth, $newHeight) | |
#save to file | |
$bmpResized.Save($imageTarget,$myImageCodecInfo, $($encoderParams)) | |
$graph.Dispose() | |
$bmpResized.Dispose() | |
$bmp.Dispose() | |
#end of resize code | |
<# | |
Different settings for the wallpaper: | |
Tile : | |
key.SetValue(@"WallpaperStyle", "0") ; | |
key.SetValue(@"TileWallpaper", "1") ; | |
break; | |
Center : | |
key.SetValue(@"WallpaperStyle", "0") ; | |
key.SetValue(@"TileWallpaper", "0") ; | |
break; | |
Stretch : | |
key.SetValue(@"WallpaperStyle", "2") ; | |
key.SetValue(@"TileWallpaper", "0") ; | |
break; | |
Fill : | |
key.SetValue(@"WallpaperStyle", "10") ; | |
key.SetValue(@"TileWallpaper", "0") ; | |
break; | |
Fit : | |
key.SetValue(@"WallpaperStyle", "6") ; | |
key.SetValue(@"TileWallpaper", "0") ; | |
break; | |
#> | |
#I recommend using "center", since the resize code above should have taken care of making the image fit perfectly | |
Write-Output "Setting Wallpaper..." | |
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name Wallpaper -value ($outpath + $outfile + "-resized.jpg" ) | |
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name WallpaperStyle -value 0 | |
Set-ItemProperty -path "HKCU:Control Panel\Desktop" -name TileWallpaper -value 0 | |
Set-ItemProperty 'HKCU:\Control Panel\Colors' -name Background -Value "0 0 0" | |
#rundll32.exe user32.dll, UpdatePerUserSystemParameters | |
$setwallpapersource = @" | |
using System.Runtime.InteropServices; | |
public class wallpaper | |
{ | |
public const int SetDesktopWallpaper = 20; | |
public const int UpdateIniFile = 0x01; | |
public const int SendWinIniChange = 0x02; | |
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | |
private static extern int SystemParametersInfo (int uAction, int uParam, string lpvParam, int fuWinIni); | |
public static void SetWallpaper ( string path ) | |
{ | |
SystemParametersInfo( SetDesktopWallpaper, 0, path, UpdateIniFile | SendWinIniChange ); | |
} | |
} | |
"@ | |
Add-Type -TypeDefinition $setwallpapersource | |
[wallpaper]::SetWallpaper(($outpath + $outfile + "-resized.jpg")) | |
Write-Output "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment