Copy link to clipboard
Copied
Hello,
I've written a python library that'd be useful in a PPro panel. If I turn this library into a command line tool, would I be able to access it via extendscript?
I assume a plug-in written in C could access the command line otherwise, but I'm unable to find any info on how to start writing plugins for PPro.
Any help would be appreciated. Thank you.
You can access the command line from PPRO through Node.js child process exec and execSync. You'll need a CEP panel with Node.js enabled, and then you can run commands like this:
...// async method
var exec = require('child_process').exec;
exec('run myCommand', {encoding: "UTF-8"}, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
console.log(err);
});
// or
// sync method
var execSync = require('child_process').execSync;
var res = execSync('run myCommand', {encoding: 'UTF-
Copy link to clipboard
Copied
You can access the command line from PPRO through Node.js child process exec and execSync. You'll need a CEP panel with Node.js enabled, and then you can run commands like this:
// async method
var exec = require('child_process').exec;
exec('run myCommand', {encoding: "UTF-8"}, function (err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
console.log(err);
});
// or
// sync method
var execSync = require('child_process').execSync;
var res = execSync('run myCommand', {encoding: 'UTF-8'});
Copy link to clipboard
Copied
That would definitely work.
Actually, node.js usage is not required; CEP provides access to command lines. [Unlike AE's ExtendScript API, PPro's ExtendScript API offers no direct command line access.]
Here's a snippet of JavaScript that has the user choose a .mogrt, then builds a command line string invoking a .py script within the panel's package, and passing it the selected file path.
var csInterface = new CSInterface();
var OSVersion = csInterface.getOSInformation();
var filetypes = new Array();
filetypes[0] = "mogrt";
var result = window.cep.fs.showOpenDialog(false,false,"Select a .mogrt file", "~/Desktop",filetypes);
var mogrtPath = result.data[0];
var extPath = csInterface.getSystemPath(SystemPath.EXTENSION);
var sep = "/";
if (OSVersion.indexOf("Windows") > 0){
sep = "\\\\";
}
var mogrtParentPath = mogrtPath.substring(0, mogrtPath.lastIndexOf(sep));
var pyPath = extPath + sep + 'Foiltop.py';
var processResult = window.cep.process.createProcess("usr/bin/python", pyPath, mogrtPath);
if (OSVersion.indexOf("Windows") >=0){
window.cep.process.createProcess("C:\\Windows\\explorer.exe", mogrtParentPath);
} else {
window.cep.process.createProcess("/usr/bin/open", mogrtParentPath);
}
var resultFileName = mogrtParentPath + sep + "Foiltop_results.txt";
var resultFileContents = window.cep.fs.readFile(resultFileName);//, cep.encoding.Base64);
if (0 === result.err) {
alert(resultFileContents.data);
} else {
alert("Failed to read results file.");
}
}