Skip to content

Commit 4946b67

Browse files
committed
Added close-chrome.ps1 and close-thunderbird.ps1
1 parent 519fbbb commit 4946b67

5 files changed

Lines changed: 34 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ The following PowerShell scripts can be found in the [Scripts/](Scripts/) subfol
1111
* [check-mac-address.ps1](Scripts/check-mac-address.ps1) - checks the given MAC address for validity
1212
* [check-xml-file.ps1](Scripts/check-xml-file.ps1) - checks the given XML file for validity
1313
* [clone-repos.ps1](Scripts/clone-repos.ps1) - clones well-known Git repositories
14+
* [close-chrome.ps1](Scripts/close-chrome.ps1) - closes Google Chrome gracefully
1415
* [close-program.ps1](Scripts/close-program.ps1) - closes the given program gracefully
16+
* [close-thunderbird.ps1](Scripts/close-thunderbird.ps1) - closes Mozilla Thunderbird gracefully
1517
* [close-windows-terminal.ps1](Scripts/close-windows-terminal.ps1) - closes Windows Terminal gracefully
1618
* [configure-git.ps1](Scripts/configure-git.ps1) - sets up the Git configuration
1719
* [csv-to-text.ps1](Scripts/csv-to-text.ps1) - converts the given CSV file into a text list

Scripts/close-chrome.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/snap/bin/powershell
2+
3+
# Syntax: ./close-chrome.ps1
4+
# Description: closes Google Chrome gracefully
5+
# Author: Markus Fleschutz
6+
# Source: github.com/fleschutz/PowerShell
7+
# License: CC0
8+
9+
$ExitCode = close-program.ps1 "chrome"
10+
exit $ExitCode

Scripts/close-program.ps1

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@ try {
1414
$ProgramName = read-host "Enter program to close"
1515
}
1616
$List = Get-Process -name $ProgramName -erroraction 'silentlycontinue'
17-
$NumProc = 0
18-
$List | Foreach-Object { $NumProc++; $_.CloseMainWindow() | Out-Null } | stop-process -force
19-
if ($NumProc -eq 0) {
20-
write-error "ERROR: No processes for program '$ProgramName' found"
21-
exit 1
22-
} else {
23-
write-output "Done - $NumProc processes stopped."
24-
exit 0
17+
$NumProcKilled = 0
18+
$List | Foreach-Object {
19+
$_.CloseMainWindow() | Out-Null
20+
$NumProcKilled++
21+
} | stop-process -force
22+
if ($NumProcKilled -eq 0) {
23+
throw "program '$ProgramName' is not started yet"
2524
}
25+
write-output "OK - program '$ProgramName' has been closed ($NumProcKilled processes)."
26+
exit 0
2627
} catch {
2728
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2829
exit 1

Scripts/close-thunderbird.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/snap/bin/powershell
2+
3+
# Syntax: ./close-thunderbird.ps1
4+
# Description: closes Mozilla Thunderbird gracefully
5+
# Author: Markus Fleschutz
6+
# Source: github.com/fleschutz/PowerShell
7+
# License: CC0
8+
9+
$ExitCode = close-program.ps1 "thunderbird"
10+
exit $ExitCode

Scripts/close-windows-terminal.ps1

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
#!/snap/bin/powershell
22

33
# Syntax: ./close-windows-terminal.ps1
4-
# Description: closes the Windows Terminal program gracefully
4+
# Description: closes Windows Terminal gracefully
55
# Author: Markus Fleschutz
66
# Source: github.com/fleschutz/PowerShell
77
# License: CC0
88

9-
close-program.ps1 "WindowsTerminal"
10-
#try {
11-
# exit 0
12-
#} catch {
13-
# write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
14-
# exit 1
15-
#}
9+
$ExitCode = close-program.ps1 "WindowsTerminal"
10+
exit $ExitCode

0 commit comments

Comments
 (0)