From 0ca0bcf2d71ecc6a5787dff29d7c414b44354d58 Mon Sep 17 00:00:00 2001 From: Markus Fleschutz Date: Wed, 20 Nov 2024 13:58:52 +0100 Subject: [PATCH] Updated play-system-sounds.ps1 --- scripts/play-system-sounds.ps1 | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/scripts/play-system-sounds.ps1 b/scripts/play-system-sounds.ps1 index d6921e42..090aa59f 100755 --- a/scripts/play-system-sounds.ps1 +++ b/scripts/play-system-sounds.ps1 @@ -2,18 +2,34 @@ .SYNOPSIS Plays all system sounds .DESCRIPTION - This PowerShell script plays all operating system sounds. + This PowerShell script plays all available system sounds. .EXAMPLE PS> ./play-system-sounds.ps1 - (listen and enjoy) + (listen and enjoy) .LINK https://github.com/fleschutz/PowerShell .NOTES 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) { - $files = (Get-ChildItem "$filePattern") + $files = Get-ChildItem "$filePattern" foreach($file in $files) { & "$PSScriptRoot/play-mp3.ps1" "$file" Start-Sleep -milliseconds 500 @@ -21,14 +37,10 @@ function PlaySoundFiles([string]$filePattern) { } try { - if ($IsLinux -or $IsMacOS) { throw "Currently only supported for Windows" } - - $WinDir = Resolve-Path "$env:WINDIR" - if (-not(Test-Path "$WinDir" -pathType container)) { throw "Windows directory at 📂$Path doesn't exist" } - - Write-Host "`n Windows System Sounds at $WinDir\Media" -foregroundColor green - PlaySoundFiles "$WinDir\Media\*.wav" - PlaySoundFiles "$WinDir\Media\*\*.wav" + $path = GetPathToSystemMedia + Write-Host "`n S Y S T E M S O U N D S (at: $path)" -foregroundColor green + PlaySoundFiles "$path\*.wav" + PlaySoundFiles "$path\*\*.wav" exit 0 # success } catch { "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"