mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-03-31 11:16:12 +02:00
Improve take-screenshot.ps1
This commit is contained in:
parent
c05fcfe32b
commit
badb85ad23
@ -13,7 +13,7 @@
|
|||||||
https://github.com/fleschutz/PowerShell
|
https://github.com/fleschutz/PowerShell
|
||||||
#>
|
#>
|
||||||
|
|
||||||
param([string]$Directory = "$PWD")
|
param([string]$Directory = "$HOME/Pictures")
|
||||||
|
|
||||||
function TakeScreenshot { param([string]$FilePath)
|
function TakeScreenshot { param([string]$FilePath)
|
||||||
Add-Type -Assembly System.Windows.Forms
|
Add-Type -Assembly System.Windows.Forms
|
||||||
@ -27,12 +27,15 @@ function TakeScreenshot { param([string]$FilePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (-not(test-path "$Directory" -pathType container)) {
|
||||||
|
throw "Target folder at 📂$Directory doesn't exist"
|
||||||
|
}
|
||||||
$Time = (Get-Date)
|
$Time = (Get-Date)
|
||||||
$Filename = "$($Time.Year)-$($Time.Month)-$($Time.Day)-$($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 $Directory $Filename)
|
||||||
|
|
||||||
write-output "Saving screenshot to $FilePath..."
|
|
||||||
TakeScreenshot $FilePath
|
TakeScreenshot $FilePath
|
||||||
|
|
||||||
|
"✔️ screenshot saved to $FilePath"
|
||||||
exit 0 # success
|
exit 0 # success
|
||||||
} catch {
|
} catch {
|
||||||
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"
|
||||||
|
Loading…
Reference in New Issue
Block a user