Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/fakoua/SwissKnife

Deno Swiss Knife tools
https://github.com/fakoua/SwissKnife

deno dialog monitor notification screen screencapture screenshot systray texttospeech typescript volume windows

Last synced: 3 months ago
JSON representation

Deno Swiss Knife tools

Awesome Lists containing this project

README

        

# SwissKnife
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/fakoua/swissKnife?style=for-the-badge)
![GitHub](https://img.shields.io/github/license/fakoua/swissKnife?style=for-the-badge)
![GitHub last commit](https://img.shields.io/github/last-commit/fakoua/swissKnife?style=for-the-badge)
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/fakoua/swissKnife/Deno%20CI?style=for-the-badge)

Deno Swiss Knife tools (Windows Only)

SwissKnife is a Deno module that allows you to do some useful tasks on Windows OS using NirCmd v2.86

[API Document](https://doc.deno.land/https/deno.land/x/swissKnife/mod.ts)

## Usage

### Sound Library

#### Text To Speech

Speaks the text your specify by using the Speech library (SAPI) that comes with Windows.

```ts
import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
await swissKnife.speak("Hello from the other world")
```

Run your script file:

```bash
deno -A myfile.ts #Requires allow-run and allow-write permissions
```

You can also set the rate and the volume:

```ts
import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"
await swissKnife.speak("Hello from the other world", {rate: 3, volume: 80})
//rate: -10 -> 10
//volume: 0% -> 100%
```

### Computer System volume

```ts
import * as swissKnife from "https://deno.land/x/swissKnife/mod.ts"

//Set the volume
await swissKnife.setVolume(90) //value between 0 to 100

//mute the system sound
await swissKnife.mute()

//unmute the system sound
await swissKnife.unmute()
```

### Play beeps

`await swissKnife.beep(freq, duration)`

The freq (Frequance) parameter specifies the freq in hertz, the duration parameter specifies the duration of the sound in milliseconds.

```ts
await swissKnife.beep(500, 1000) //play 500 hz for 1 sec.
```

Also you can play the Windows standard beep (notification sound)

```ts
await swissKnife.winBeep()
```

### Play local mp3

`await swissKnife.playMp3(local_path)`

Play local mp3 and WAIT untile the sound ends..

```ts
await swissKnife.playMp3("c:\\myFolder\\sound.mp3") //play 500 hz for 1 sec.
```

## Desktop Library

### Take screenshot

With swissKnife you can take a screenshot of the full screen, dual screen and active windows and save the png file to your hard disk.

```ts
//Save the primary screen image.
await swissKnife.screenshot("c:\\myfolder\\myfile.png")
```

Also you can specify Dual monitor:

```ts
//take a screenshot of both screens
await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Dual")
```

Also you can specify the current active window:

```ts
//take a screenshot of both screens
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
await swissKnife.screenshot("c:\\myfolder\\myfile.png", "Single", {
x: 10,
y: 30,
width: 200,
height: 150
})
```

### Show Notification (Tray Balloon)

Display a notification with text, icon and duration:

`swissKnife.notification(title, text, iconNumber, duration)`

NB: Icon number is the icon id in shell32.dll

```ts
await swissKnife.notification("My Title", "Hello Notification", 77, 2000)
```

### Show info box

Display a dialog box with "OK" button:

`await swissKnife.infoBox(title, text)`

### Question Box

Question box is a dialog box with "yes/no" buttons that returns true if the user clicks on yes

```ts
let res = await swissKnife.questionBox("A Question", "Do you want to quite smoking?")
if (res) {
console.log("Great, keep trying!")
} else {
console.log("Not Great, but keep trying!")
}
```

## Window (forms) Actions Library

This method allows you to hide, show, minimize, maximize, flush ... windows forms.

`winAction(winTitle: string, find: Find, action: WinActions)`

- winTitle: Window Title to send the command
- find: Find method (Contains, StartsWith, EndsWith and Equals)
- action: Close, Hide, Show, Activate, Flash, Max, Min, Normal and Center.

```ts
//flash any window with title containing 'untit'
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)

[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Ffakoua%2FSwissKnife.svg?type=large)](https://app.fossa.com/projects/git%2Bgithub.com%2Ffakoua%2FSwissKnife?ref=badge_large)