PowerShell/scripts/change-wallpaper.ps1

38 lines
983 B
PowerShell
Raw Normal View History

2024-10-01 15:11:03 +02:00
<#
2021-12-11 16:49:04 +01:00
.SYNOPSIS
2021-12-13 10:03:37 +01:00
Changes the wallpaper
2021-12-11 16:49:04 +01:00
.DESCRIPTION
2022-01-29 12:47:46 +01:00
This PowerShell script downloads a random photo from Unsplash and sets it as desktop background.
2021-12-12 12:17:30 +01:00
.PARAMETER Category
Specifies the photo category (beach, city, ...)
2021-12-11 16:49:04 +01:00
.EXAMPLE
2021-12-13 10:03:37 +01:00
PS> ./change-wallpaper
2021-12-11 16:49:04 +01:00
.LINK
https://github.com/fleschutz/PowerShell
2022-09-06 21:42:04 +02:00
.NOTES
Author: Markus Fleschutz | License: CC0
2021-12-11 16:49:04 +01:00
#>
2021-12-12 12:17:30 +01:00
param([string]$Category = "")
2021-12-11 16:49:04 +01:00
function GetTempDir {
if ("$env:TEMP" -ne "") { return "$env:TEMP" }
if ("$env:TMP" -ne "") { return "$env:TMP" }
if ($IsLinux) { return "/tmp" }
return "C:\Temp"
}
try {
2022-11-18 16:54:04 +01:00
& "$PSScriptRoot/speak-english.ps1" "Just a second..."
2021-12-11 17:14:27 +01:00
2021-12-11 16:49:04 +01:00
$Path = "$(GetTempDir)/next_wallpaper.jpg"
2021-12-12 12:17:30 +01:00
& wget -O $Path "https://source.unsplash.com/3840x2160?$Category"
2021-12-12 11:37:40 +01:00
if ($lastExitCode -ne "0") { throw "Download failed" }
2021-12-11 16:49:04 +01:00
2021-12-12 11:37:40 +01:00
& "$PSScriptRoot/set-wallpaper.ps1" -ImageFile "$Path"
2021-12-11 16:49:04 +01:00
exit 0 # success
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2021-12-11 16:49:04 +01:00
exit 1
}