sleep-timer.ps1

#749
Raw
Author
Anonymous
Created
May 8, 2023, 7:05 a.m.
Expires
Never
Size
494 bytes
Hits
71
Syntax
PowerShell
Private
No
# Play music while going to sleep.
# 1. Ensure you have your music playing.
# 2. Run this script - i.e. & .\sleep-timer.ps1
# 3. Music will pause, computer will suspend after 1 hour.
Add-Type -AssemblyName System.Windows.Forms

$ts = New-Timespan -Hours 1
Start-Sleep -Duration $ts
$wshShell = new-object -com wscript.shell
$wshShell.SendKeys([char]179)
[System.Windows.Forms.Application]::SetSuspendState(
    [System.Windows.Forms.PowerState]::Suspend,
    $true,
    $false
)