Created
November 27, 2013 02:01
-
-
Save nbqx/7669570 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Writable = require('stream').Writable, | |
TmpFile = require('temporary').File, | |
exec = require('child_process').exec, | |
util = require('util'); | |
util.inherits(InDesignWritableStream, Writable); | |
function InDesignWritableStream(opt){ | |
var self = this; | |
self.cmd = ['osascript']; | |
self.jsx = new TmpFile(); | |
self.scpt = new TmpFile(); | |
Writable.call(self, opt); | |
}; | |
InDesignWritableStream.prototype._write = function(data,encoding,done){ | |
var self = this; | |
self.jsx.writeFileSync(data); | |
var script = [ | |
"tell application \"Adobe InDesign CS5\"", | |
" with timeout (1 * 60 * 60) seconds", | |
" do script \"$.evalFile('"+self.jsx.path+"');\" language javascript", | |
" end timeout", | |
"end tell" | |
].join("\n"); | |
self.scpt.writeFileSync(script); | |
self.cmd.push(self.scpt.path); | |
var cmd = self.cmd.join(' '); | |
exec(cmd, function(err,stdout,stderr){ | |
if(err) return new Error(err); | |
if(stderr) console.log(stderr); | |
if(stdout) console.log(stdout); | |
self.jsx.unlink(); | |
self.scpt.unlink(); | |
done(); | |
}); | |
}; | |
module.exports = InDesignWritableStream; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'), | |
InDesignWritableStream = require(__dirname+'/indesign_writable_stream'); | |
var jsx = fs.createReadStream(__dirname+"/test.jsx"); | |
var ind = new InDesignWritableStream(); | |
jsx.pipe(ind); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#target InDesign-7.0 | |
alert('this is indesign script'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment