Update save-screenshot.ps1

This commit is contained in:
Markus Fleschutz 2021-10-20 13:52:08 +02:00 committed by GitHub
parent a69e3c3bc1
commit e6f49215f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,8 +3,8 @@
Saves a single screenshot Saves a single screenshot
.DESCRIPTION .DESCRIPTION
This script takes a single screenshot and saves it into a target folder (the user's pictures folder by default). This script takes a single screenshot and saves it into a target folder (the user's pictures folder by default).
.PARAMETER Directory .PARAMETER TargetFolder
Specifies the target directory (the user's pictures folder by default) Specifies the target folder (the user's pictures folder by default)
.EXAMPLE .EXAMPLE
PS> ./save-screenshot PS> ./save-screenshot
screenshot saved to C:\Users\Markus\Pictures\2021-10-10T14-33-22.png screenshot saved to C:\Users\Markus\Pictures\2021-10-10T14-33-22.png
@ -14,7 +14,7 @@
https://github.com/fleschutz/PowerShell https://github.com/fleschutz/PowerShell
#> #>
param([string]$Directory = "$HOME/Pictures") param([string]$TargetFolder = "$HOME/Pictures")
function TakeScreenshot { param([string]$FilePath) function TakeScreenshot { param([string]$FilePath)
Add-Type -Assembly System.Windows.Forms Add-Type -Assembly System.Windows.Forms
@ -28,12 +28,12 @@ function TakeScreenshot { param([string]$FilePath)
} }
try { try {
if (-not(test-path "$Directory" -pathType container)) { if (-not(test-path "$TargetFolder" -pathType container)) {
throw "Target folder at 📂$Directory doesn't exist" throw "Target folder at 📂$TargetFolder doesn't exist"
} }
$Time = (Get-Date) $Time = (Get-Date)
$Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)T$($Time.Hour)-$($Time.Minute)-$($Time.Second).png" $Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)T$($Time.Hour)-$($Time.Minute)-$($Time.Second).png"
$FilePath = (Join-Path $Directory $Filename) $FilePath = (Join-Path $TargetFolder $Filename)
TakeScreenshot $FilePath TakeScreenshot $FilePath
"✔️ screenshot saved to $FilePath" "✔️ screenshot saved to $FilePath"