Updated play-system-sounds.ps1

This commit is contained in:
Markus Fleschutz 2024-11-20 13:58:52 +01:00
parent 30ebcd6d87
commit 0ca0bcf2d7

View File

@ -2,7 +2,7 @@
.SYNOPSIS .SYNOPSIS
Plays all system sounds Plays all system sounds
.DESCRIPTION .DESCRIPTION
This PowerShell script plays all operating system sounds. This PowerShell script plays all available system sounds.
.EXAMPLE .EXAMPLE
PS> ./play-system-sounds.ps1 PS> ./play-system-sounds.ps1
(listen and enjoy) (listen and enjoy)
@ -12,8 +12,24 @@
Author: Markus Fleschutz | License: CC0 Author: Markus Fleschutz | License: CC0
#> #>
function GetPathToSystemMedia {
if ($IsLinux) {
throw "Not supported for Linux yet"
} elseif ($IsMacOS) {
throw "Not supported for MacOS yet"
} else {
$WinPath = Resolve-Path "$env:WINDIR"
if (-not(Test-Path "$WinPath" -pathType container)) { throw "Windows folder at 📂$WinPath doesn't exist" }
$MediaPath = "$WinPath\Media"
if (-not(Test-Path "$MediaPath" -pathType container)) { throw "Windows media at 📂$MediaPath doesn't exist" }
return $MediaPath
}
}
function PlaySoundFiles([string]$filePattern) { function PlaySoundFiles([string]$filePattern) {
$files = (Get-ChildItem "$filePattern") $files = Get-ChildItem "$filePattern"
foreach($file in $files) { foreach($file in $files) {
& "$PSScriptRoot/play-mp3.ps1" "$file" & "$PSScriptRoot/play-mp3.ps1" "$file"
Start-Sleep -milliseconds 500 Start-Sleep -milliseconds 500
@ -21,14 +37,10 @@ function PlaySoundFiles([string]$filePattern) {
} }
try { try {
if ($IsLinux -or $IsMacOS) { throw "Currently only supported for Windows" } $path = GetPathToSystemMedia
Write-Host "`n S Y S T E M S O U N D S (at: $path)" -foregroundColor green
$WinDir = Resolve-Path "$env:WINDIR" PlaySoundFiles "$path\*.wav"
if (-not(Test-Path "$WinDir" -pathType container)) { throw "Windows directory at 📂$Path doesn't exist" } PlaySoundFiles "$path\*\*.wav"
Write-Host "`n Windows System Sounds at $WinDir\Media" -foregroundColor green
PlaySoundFiles "$WinDir\Media\*.wav"
PlaySoundFiles "$WinDir\Media\*\*.wav"
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"