-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cli.js
executable file
·43 lines (35 loc) · 912 Bytes
/
cli.js
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
36
37
38
39
40
41
42
43
#!/usr/bin/env node
import process from 'node:process';
import meow from 'meow';
import {activeWindow} from 'get-windows';
const cli = meow(`
Usage
$ active-window [property]
Returns title, id, app, pid, or the specified property
Examples
$ active-window
npm install
54
Terminal
368
$ active-window app
Terminal
`, {
importMeta: import.meta,
});
const returnValue = await activeWindow();
const validProperties = ['title', 'id', 'app', 'pid'];
const property = cli.input[0];
if (!returnValue) {
console.log('Could not find an active window.');
process.exit(1);
}
if (property) {
if (!validProperties.includes(property)) {
console.error(`Specify a valid property: ${validProperties.join(', ')}`);
process.exit(1);
}
console.log(returnValue[property]);
process.exit();
}
console.log(`${returnValue.title}\n${returnValue.id}\n${returnValue.app}\n${returnValue.pid}`);