Skip to content

Instantly share code, notes, and snippets.

@jimjam-slam
Last active August 1, 2018 14:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimjam-slam/ccb5861274d0034339b201294b7e416a to your computer and use it in GitHub Desktop.
Save jimjam-slam/ccb5861274d0034339b201294b7e416a to your computer and use it in GitHub Desktop.
Download (nearly) the latest Himawari Day + Night satellite imagery, crop it around Australia/NZ (for a 3:2 screen) and set the Windows desktop wallpaper with it.
# powershell script to get latest himawari imagery as a wallpaper.
# either run manually or use with task scheduler (but not *too* often!) like:
# powershell.exe -ExecutionPolicy Bypass -NonInteractive -WindowStyle Hidden -File C:\Users\rensa\himawari-wallpaper.ps1 -wallpaperdir C:\Users\rensa\Pictures\wallpapers
# create a himawari subfolder, change the windows wallpaper to slideshow and point it to this subfolder
# remember to respect the bom's anon ftp policy! http://www.bom.gov.au/catalogue/anon-ftp.shtml
param (
[String]$wallpaperdir = "C:\Users\Public\Pictures\wallpapers"
)
# get date-time in utc an hour ago; round down to 10-min block
$dl_date = [DateTime]::UtcNow.AddHours(-1) | get-date -Format "yyyyMMddHHmm"
$dl_date = $dl_date.Substring(0, 11) + "0"
# download the image
if (Test-Path ($wallpaperdir + "\himawari.jpg")) { Remove-Item ($wallpaperdir + "\himawari.jpg") }
Invoke-WebRequest -Uri ("ftp://ftp.bom.gov.au/anon/gen/gms/IDE00406." + $dl_date + ".jpg") -OutFile ($wallpaperdir + "\himawari.jpg")
# load the image
$latest = New-Object -ComObject Wia.ImageFile
$latest.LoadFile($wallpaperdir + "\himawari.jpg")
# build a 3000x2000 cropping filter
$crop_32 = New-Object -ComObject Wia.ImageProcess
$crop_32.Filters.Add($crop_32.FilterInfos("Crop").FilterID)
$crop_32.Filters(1).Properties("Left") = 750
$crop_32.Filters(1).Properties("Top") = 950
$crop_32.Filters(1).Properties("Right") = $latest.Width - (750 + 4500)
$crop_32.Filters(1).Properties("Bottom") = $latest.Height - (950 + 3000)
# crop the file and write it out to disk (delete existing if necessary)
$latest_cropped_32 = $crop_32.Apply($latest)
if (Test-Path ($wallpaperdir + "\himawari\3-2.jpg")) { Remove-Item ($wallpaperdir + "\himawari\3-2.jpg") }
$latest_cropped_32.SaveFile($wallpaperdir + "\himawari\3-2.jpg")
# also make a copy so that windows desktop rotator will actually switch
Copy-Item ($wallpaperdir + "\himawari\3-2.jpg") -Destination ($wallpaperdir + "\himawari\3-2b.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment