-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathcapture_exec.js
More file actions
37 lines (33 loc) · 1.01 KB
/
capture_exec.js
File metadata and controls
37 lines (33 loc) · 1.01 KB
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
var exec = require('child_process').exec
var os = require('os')
var fs = require('fs')
var path = require('path')
// freeware nircmd http://www.nirsoft.net/utils/nircmd.html
var nircmdc = path.resolve(__dirname, '../bin/nircmdc.exe')
function captureCommand (path) {
switch (os.platform()) {
case 'win32':
return '"' + nircmdc + '" savescreenshot ' + path
case 'freebsd':
return 'scrot -s ' + path
case 'darwin':
return 'screencapture -S -x ' + path
case 'linux':
return 'import ' + path
default:
throw new Error('unsupported platform')
}
}
exports.capture = function (filePath, callback) {
exec(captureCommand(filePath), function (err) {
// nircmd always exits with err even though it works
if (err && os.platform() !== 'win32') callback(err)
fs.exists(filePath, function (exists) {
// check exists for success/fail instead
if (!exists) {
return callback(new Error('Screenshot failed'))
}
callback(null, filePath)
})
})
}