-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaffeinate.ps1
35 lines (28 loc) · 994 Bytes
/
caffeinate.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function Drink-Espresso {
Write-Host "[info] Currently ordering a double shot of espresso..."
$Signature=@"
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
public static extern void SetThreadExecutionState(uint esFlags);
"@
$ES_DISPLAY_REQUIRED = [uint32]"0x00000002"
$ES_CONTINUOUS = [uint32]"0x80000000"
$JobName = "DrinkALotOfEspresso"
try
{
$BackgroundJob = Start-Job -Name $JobName -ScriptBlock {
$STES = Add-Type -MemberDefinition $args[0] -Name System -Namespace Win32 -PassThru
$STES::SetThreadExecutionState($args[2] -bor $args[1])
while ($true)
{
Start-Sleep -s 15
}
} -ArgumentList $Signature, $ES_DISPLAY_REQUIRED, $ES_CONTINUOUS
Wait-Job $BackgroundJob
}
finally
{
Stop-Job -Name $JobName
Remove-Job -Name $JobName
Write-Host "[info] No more espressos left behind the counter."
}
}