Skip to content

Commit

Permalink
Merge pull request #5 from johnvmt/darwin
Browse files Browse the repository at this point in the history
Darwin
  • Loading branch information
johnvmt authored Aug 28, 2016
2 parents 786cdb7 + 267f65e commit ec28f71
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
37 changes: 20 additions & 17 deletions capture/darwin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = function(options, callback) {

var path = require('path');
var fs = require('fs');
var childProcess = require('child_process');
Expand Down Expand Up @@ -35,22 +34,26 @@ module.exports = function(options, callback) {
}

function capture(output, callback) {
var cmd = "screencapture"
+ " -t " + path.extname(output).toLowerCase().substring(1) // will create PNG by default
+ " -x " + output;

childProcess.exec(cmd, function(error, stdout, stderr) {
if(error)
callback(error, null);
else {
try {
fs.statSync(output);
callback(null, true);
}
catch (error) {
callback(error, null);
}
}
var cmd = "screencapture";
var args = [
// will create PNG by default
"-t",
path.extname(output).toLowerCase().substring(1),
"-x",
output
];

var captureChild = childProcess.spawn(cmd, args);

captureChild.on('close', function(error) {
if (error)
callback(error.toString());
else
callback();
});

captureChild.stderr.on('data', function(data) {
callback(data.toString());
});
}
};
4 changes: 2 additions & 2 deletions module.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = function() {
return new Screenshot(arguments);
};

var path = require('path');
var path = require('flavored-path');
var jimp = require('jimp');
var fs = require('fs');

Expand Down Expand Up @@ -94,7 +94,7 @@ Screenshot.prototype.parseArgs = function(args) {
config.options.output = file;

if(typeof config.options.output === "string")
config.options.output = path.resolve(config.options.output);
config.options.output = path.normalize(config.options.output);

return config;
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "desktop-screenshot",
"version": "0.1.0",
"version": "0.1.1",
"description": "Cross-platform screenshot module, using external tools",
"license": "MIT",
"author": {
Expand All @@ -12,7 +12,8 @@
"url": "https://github.com/johnvmt/node-desktop-screenshot"
},
"dependencies": {
"jimp": "0.2.x"
"jimp": "0.2.x",
"flavored-path": "0.0.x"
},
"main": "module.js"
}

0 comments on commit ec28f71

Please sign in to comment.