-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
65 lines (59 loc) · 1.27 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const {spawn, spawnSync} = require("child_process")
let config
switch (process.platform) {
case 'darwin':
config = require('./platform/darwin')
break
case 'win32':
config = require('./platform/win32')
break
case 'linux':
config = require('./platform/linux')
break
default:
throw new Error('Unknown platform: ' + process.platform)
}
function cmd(args) {
const app = args[0]
args = args.slice(1)
const {stdout, stderr, status} = spawnSync(app, args)
if (status !== 0) throw stderr
return stdout
}
function cmd2(args2) {
for (let i in args2) {
let args = args2[i]
const app = args[0]
args = args.slice(1)
// console.log(app, args)
const {stderr, status} = spawnSync(app, args)
if (status !== 0) {
if (process.platform === 'linux') {
console.warn('** Linux needs `xdotool`')
}
throw stderr
}
}
}
function send(keys, metaKeys) {
cmd(config.send(keys, metaKeys))
}
function activate(title) {
cmd(config.activate(title))
}
function run(path) {
return cmd(config.run(path))
}
function sleep(v) {
cmd(config.sleep(v))
}
function sendKeys(keys) {
cmd2(config.sendKeys(keys))
}
module.exports = {
'sendKeys': sendKeys,
'send': send,
'activate': activate,
'run': run,
'sleep': sleep
}