PowerShell/scripts/play-system-sounds.ps1

49 lines
1.2 KiB
PowerShell
Raw Normal View History

2024-10-01 15:24:16 +02:00
<#
2024-04-24 20:00:49 +02:00
.SYNOPSIS
Plays all system sounds
.DESCRIPTION
2024-11-20 13:58:52 +01:00
This PowerShell script plays all available system sounds.
2024-04-24 20:00:49 +02:00
.EXAMPLE
PS> ./play-system-sounds.ps1
2024-11-20 13:58:52 +01:00
(listen and enjoy)
2024-04-24 20:00:49 +02:00
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
2024-11-20 13:58:52 +01:00
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
}
}
2024-04-24 20:00:49 +02:00
function PlaySoundFiles([string]$filePattern) {
2024-11-20 13:58:52 +01:00
$files = Get-ChildItem "$filePattern"
2024-04-24 20:00:49 +02:00
foreach($file in $files) {
& "$PSScriptRoot/play-mp3.ps1" "$file"
Start-Sleep -milliseconds 500
}
}
try {
2024-11-20 13:58:52 +01:00
$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"
2024-04-24 20:00:49 +02:00
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}