mirror of
https://github.com/fleschutz/PowerShell.git
synced 2025-04-20 08:58:18 +02:00
Add set-volume.ps1
This commit is contained in:
parent
0288614b8d
commit
108128cd51
37
Scripts/set-volume.ps1
Normal file
37
Scripts/set-volume.ps1
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<#
|
||||||
|
.SYNOPSIS
|
||||||
|
Sets the volume
|
||||||
|
.DESCRIPTION
|
||||||
|
This PowerShell script sets the audio volume in percent.
|
||||||
|
.PARAMETER volume
|
||||||
|
Specifies the percent number
|
||||||
|
.EXAMPLE
|
||||||
|
PS> ./set-volume 50
|
||||||
|
.LINK
|
||||||
|
https://github.com/fleschutz/PowerShell
|
||||||
|
.NOTES
|
||||||
|
Author: Markus Fleschutz | License: CC0
|
||||||
|
#>
|
||||||
|
|
||||||
|
Param([Parameter(Mandatory=$true)] [ValidateRange(0,100)] [Int] $Volume)
|
||||||
|
|
||||||
|
try {
|
||||||
|
# Create the Windows Shell object.
|
||||||
|
$obj = New-Object -ComObject WScript.Shell
|
||||||
|
|
||||||
|
# First, set volume to zero.
|
||||||
|
1..50 | ForEach-Object { $obj.SendKeys( [char] 174 ) }
|
||||||
|
|
||||||
|
# Calculate number of (volume up) key presses
|
||||||
|
$keyPresses = [Math]::Ceiling( $Volume / 2 )
|
||||||
|
|
||||||
|
# Raise volume to specified level.
|
||||||
|
for( $i = 0; $i -lt $keyPresses; $i++ ) {
|
||||||
|
$obj.SendKeys( [char] 175 )
|
||||||
|
}
|
||||||
|
& "$PSScriptRoot/give-reply.ps1" "$($Volume)% volume."
|
||||||
|
exit 0 # success
|
||||||
|
} catch {
|
||||||
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||||
|
exit 1
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user