Skip to content

Instantly share code, notes, and snippets.

@bo33b
Last active March 27, 2024 18:35
Show Gist options
  • Save bo33b/7fae8154a26588714b48a92a6fec0e3b to your computer and use it in GitHub Desktop.
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
// ==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