2022-12-04 10:40:18 +01:00
|
|
|
## The *change-wallpaper.ps1* Script
|
2022-02-10 09:01:07 +01:00
|
|
|
|
|
|
|
This PowerShell script downloads a random photo from Unsplash and sets it as desktop background.
|
|
|
|
|
|
|
|
## Parameters
|
|
|
|
```powershell
|
|
|
|
change-wallpaper.ps1 [[-Category] <String>] [<CommonParameters>]
|
|
|
|
|
|
|
|
-Category <String>
|
|
|
|
Specifies the photo category (beach, city, ...)
|
|
|
|
|
|
|
|
Required? false
|
|
|
|
Position? 1
|
|
|
|
Default value
|
|
|
|
Accept pipeline input? false
|
|
|
|
Accept wildcard characters? false
|
|
|
|
|
|
|
|
[<CommonParameters>]
|
|
|
|
This script supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, WarningAction,
|
|
|
|
WarningVariable, OutBuffer, PipelineVariable, and OutVariable.
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
```powershell
|
|
|
|
PS> ./change-wallpaper
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
## Notes
|
2022-11-17 19:46:02 +01:00
|
|
|
Author: Markus Fleschutz | License: CC0
|
2022-02-10 09:01:07 +01:00
|
|
|
|
|
|
|
## Related Links
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
2022-11-17 20:02:26 +01:00
|
|
|
## Source Code
|
2022-11-17 20:05:34 +01:00
|
|
|
```powershell
|
2022-11-17 20:02:26 +01:00
|
|
|
<#
|
|
|
|
.SYNOPSIS
|
|
|
|
Changes the wallpaper
|
|
|
|
.DESCRIPTION
|
|
|
|
This PowerShell script downloads a random photo from Unsplash and sets it as desktop background.
|
|
|
|
.PARAMETER Category
|
|
|
|
Specifies the photo category (beach, city, ...)
|
|
|
|
.EXAMPLE
|
|
|
|
PS> ./change-wallpaper
|
|
|
|
.LINK
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
.NOTES
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
#>
|
|
|
|
|
|
|
|
param([string]$Category = "")
|
|
|
|
|
|
|
|
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 17:02:20 +01:00
|
|
|
& "$PSScriptRoot/speak-english.ps1" "Just a second..."
|
2022-11-17 20:02:26 +01:00
|
|
|
|
|
|
|
$Path = "$(GetTempDir)/next_wallpaper.jpg"
|
|
|
|
& wget -O $Path "https://source.unsplash.com/3840x2160?$Category"
|
|
|
|
if ($lastExitCode -ne "0") { throw "Download failed" }
|
|
|
|
|
|
|
|
& "$PSScriptRoot/set-wallpaper.ps1" -ImageFile "$Path"
|
|
|
|
exit 0 # success
|
|
|
|
} catch {
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-11-17 20:05:34 +01:00
|
|
|
```
|
2022-11-17 20:02:26 +01:00
|
|
|
|
2022-02-10 09:01:07 +01:00
|
|
|
*Generated by convert-ps2md.ps1 using the comment-based help of change-wallpaper.ps1*
|