-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (35 loc) · 854 Bytes
/
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
var fs = require('fs')
var exec = require('child_process').exec
var PassThrough = require('stream').PassThrough
module.exports = capture
module.exports.createReadStream = createReadStream
function createReadStream() {
var out = new PassThrough()
capture(function(err, read) {
if (err) {
out.emit('error', err)
return
}
read.pipe(out)
})
return out
}
function capture(cb) {
switch (process.platform) {
case 'darwin':
return captureDarwin(cb)
default:
return cb(new Error(process.platform + " not supported yet"))
}
}
function captureDarwin(cb) {
var time = new Date().toISOString()
var fpath = '/tmp/ss-' + time + '.png'
var cmd = 'screencapture -i ' + fpath
exec(cmd, function(err, stdout, stderr) {
if (err) {
return cb(err)
}
cb(null, fs.createReadStream(fpath))
})
}