Last active
March 27, 2024 18:35
-
-
Save bo33b/7fae8154a26588714b48a92a6fec0e3b to your computer and use it in GitHub Desktop.
This is a Vicki (getvicki.net) script to enable turning off your PC monitors
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==VickiScript== | |
// @name Turn off the monitor | |
// @version 1.2 | |
// @description Turn off all computer monitors. | |
// @utterance Ask $invocation to turn off the monitor | |
// @permission native | |
// @id custom.monitorOff | |
// @icon /res/icons/script_native.png | |
// ==/VickiScript== | |
$vs.listen.precondition(() => ["win", "mac"].some(os => os === $vs.native.os)); | |
$vs.listen(/^(?:shut|turn|switch) (?:off|of)(?: my| the)? (?:display|monitor|screen)s?$/, async (req, res) => { | |
$vs.native.assertAvailable(); | |
res.send(); | |
await monitorOff(); | |
}); | |
async function monitorOff() { | |
if ($vs.native.os === "win") { | |
await $vs.native.exec(`powershell (Add-Type '[DllImport("""user32.dll""")]public static extern int PostMessage(int h,int m,int w,int l);' -Name a -Pas)::PostMessage(0xFFFF,0x0112,0xF170,2)`); | |
} else if ($vs.native.os === "mac") { | |
await $vs.native.exec(`pmset displaysleepnow`); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment