diff --git a/README.md b/README.md index ee128d0..bc45a84 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Speaks the text your specify by using the Speech library (SAPI) that comes with ```ts import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts" -let res = await swissKnife.speak("Hello from the other world") +await swissKnife.speak("Hello from the other world") ``` Run your script file: @@ -34,7 +34,7 @@ You can also set the rate and the volume: ```ts import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts" -let res = await swissKnife.speak("Hello from the other world", {rate: 3, volume: 80}) +await swissKnife.speak("Hello from the other world", {rate: 3, volume: 80}) //rate: -10 -> 10 //volume: 0% -> 100% ``` @@ -88,28 +88,28 @@ With swissKnife you can take a screenshot of the full screen, dual screen and ac ```ts //Save the primary screen image. -let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png") +await swissKnife.screenshot("c:\\myfolder\\myfile.png") ``` Also you can specify Dual monitor: ```ts //take a screenshot of both screens -let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Dual") +await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Dual") ``` Also you can specify the current active window: ```ts //take a screenshot of both screens -let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Window") +await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Window") ``` The third parameter allows you to specify the coordinates, width and height of the area: ```ts //take a screenshot of both screens -let res = await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Single", { +await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Single", { x: 10, y: 30, width: 200, @@ -163,6 +163,19 @@ This method allows you to hide, show, minimize, maximize, flush ... windows form await swissKnife.winAction("Untit", "Contains", "Flash") ``` +## Window Power +This method allows you to Logoff, Power Off and Stand by the system. + +`power(mode:PowerMode)` + +- mode: Supported values Logoff, Power off and Standby + +```ts +import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts" +//Standby the system +await swissKnife.power("StandBy") +``` + ## License [MIT](LICENSE) diff --git a/mod.ts b/mod.ts index 9512e41..fe0e6ca 100644 --- a/mod.ts +++ b/mod.ts @@ -3,6 +3,7 @@ import type { Screen, Monitor } from "./src/models/screen.ts" import type { SpeakOptions } from "./src/models/speakOptions.ts" import type { Find } from "./src/models/findMode.ts" import type { WinActions } from "./src/models/winActions.ts" +import { PowerMode } from "./src/models/powerMode.ts"; /** @@ -327,6 +328,64 @@ export async function playMp3(mp3Path: string): Promise { return exitCode === 0 } + +/** + * Turn off the monitor + * @date 12/23/2023 - 4:28:24 PM + * + * @example + * ```ts + * import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts" + * await swissKnife.monitorOff() //turn off the monitor + * ``` + * @export + * @async + * @returns {Promise} process exit code. + */ +export async function monitorOff(): Promise { + const args = [ + "monitor", + "off", + ] + const exitCode = await runNirCmd(args); + return exitCode +} + + +/** + * Windows Power + * @date 12/23/2023 - 4:35:59 PM + * + * @example + * ```ts + * import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts" + * await swissKnife.power("StandBy") //Windows standby + * //Supported: StandBy, Logoff and Poweroff + * ``` + * @export + * @async + * @param {PowerMode} mode standby, logoff, poweroff + * @returns {Promise} process exit code + */ +export async function power(mode:PowerMode): Promise { + const args = []; + switch (mode) { + case "Logoff": + args.push("exitwin") + args.push("logoff") + break; + case "StandBy": + args.push("standby") + break; + case "PowerOff": + args.push("exitwin") + args.push("poweroff") + break; + } + const exitCode = await runNirCmd(args); + return exitCode +} + async function runNirCmd(args: Array): Promise { const OS = utils.getOS(); diff --git a/src/models/powerMode.ts b/src/models/powerMode.ts new file mode 100644 index 0000000..e50bbbe --- /dev/null +++ b/src/models/powerMode.ts @@ -0,0 +1 @@ +export type PowerMode = "StandBy" | "Logoff" | "PowerOff" \ No newline at end of file