Skip to content

Instantly share code, notes, and snippets.

@emptyother
Created July 12, 2019 22:09
Show Gist options
  • Save emptyother/df8f0cfeb923a5b608eb2d93293d8e07 to your computer and use it in GitHub Desktop.
Save emptyother/df8f0cfeb923a5b608eb2d93293d8e07 to your computer and use it in GitHub Desktop.
[Read-BeepFile] Powershell script to read a text file and beep based on the content #powershell
<#
.Synopsis
Reads a file, and beeps on 0 or 1.
.Description
Reads a textfile, beeps once for every 0 and twice for 1 it finds in the text.
.Parameter Path
The file to read
.Inputs
System.IO.FileInfo
.Example
Read-BeepFile -Path .\beep.txt
#>
[Cmdletbinding()]
Param(
[Parameter(Mandatory)]
[System.IO.FileInfo]
$Path
)
Begin {
function singleBeep {
[console]::beep(500, 500)
}
function doubleBeep {
[console]::beep(450, 200)
Start-Sleep -Milliseconds 50
[console]::beep(450, 200)
}
}
Process {
Try {
Get-Content $Path -Encoding Byte | ForEach-Object {
$currentchar = [char]$_
Write-Output $currentchar
if ($currentchar -eq "0") { singleBeep }
if ($currentchar -eq "1") { doubleBeep }
Start-Sleep -Milliseconds 700
}
}
Catch {
Write-Error $_
}
}
End { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment