PowerShell/scripts/play-system-sounds.ps1

37 lines
997 B
PowerShell
Raw Normal View History

2024-04-24 20:00:49 +02:00
<#
.SYNOPSIS
Plays all system sounds
.DESCRIPTION
This PowerShell script plays all operating system sounds.
.EXAMPLE
PS> ./play-system-sounds.ps1
(listen and enjoy)
.LINK
https://github.com/fleschutz/PowerShell
.NOTES
Author: Markus Fleschutz | License: CC0
#>
function PlaySoundFiles([string]$filePattern) {
$files = (Get-ChildItem "$filePattern")
foreach($file in $files) {
& "$PSScriptRoot/play-mp3.ps1" "$file"
Start-Sleep -milliseconds 500
}
}
try {
2024-04-25 07:16:48 +02:00
if ($IsLinux -or $IsMacOS) { throw "Currently only supported for Windows" }
2024-04-24 20:00:49 +02:00
$WinDir = Resolve-Path "$env:WINDIR"
if (-not(Test-Path "$WinDir" -pathType container)) { throw "Windows directory at 📂$Path doesn't exist" }
2024-04-25 07:16:48 +02:00
Write-Host "`n Windows System Sounds at $WinDir\Media" -foregroundColor green
2024-04-24 20:00:49 +02:00
PlaySoundFiles "$WinDir\Media\*.wav"
PlaySoundFiles "$WinDir\Media\*\*.wav"
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}