Copy link to clipboard
Copied
Hello there,
I'm trying to execute script via cmd terminal & in script I need to read and write file to certain dir basically create a copy of exising work, while checking arguments length is returning 0, as an example here is my script which reads AI file from my local and create an svg write it to destination path, but still getting arguments undefined, Can someone guide me how to get value in scripts from passed string in cmd
Example Script
if (arguments.length < 2) {
alert("Insufficient arguments provided. Expected source and destination file paths.");
quit();
}
try {
var sourceFilePath = arguments[0];
var destFilePath = arguments[1];
var sourceFile = File(sourceFilePath);
var destFile = File(destFilePath);
$.writeln("Source file: " + sourceFile.fsName);
$.writeln("Destination file: " + destFile.fsName);
if (sourceFile.exists) {
var doc = app.open(sourceFile);
var options = new ExportOptionsSVG();
var type = ExportType.SVG;
options.embedRasterImages = true;
doc.exportFile(destFile, type, options);
doc.close(SaveOptions.DONOTSAVECHANGES);
$.writeln("Export successful!");
} else {
$.writeln("Source file does not exist.");
}
} catch (e) {
$.writeln("Error: " + e.message);
}
Terminal
C:\Users\Desktop\ProjectScript>"C:\\Program Files\\Adobe\\Adobe Illustrator CS6 (64 Bit)\\Support Files\\Contents\\Windows\\Illustrator.exe" -r "C:\\Users\\Desktop\\ProjectScript\\src\\Test.jsx" "C:\\Users\\Desktop\\ProjectScript\\assets\\AI_SAMPLE.ai" "C:\\Users\\Desktop\\ProjectScript\\assets\\converted\\SVG_SAMPLE.svg"
Thanks
Copy link to clipboard
Copied
arguments does not refer to command line, it's specifically referring only to in-scope parameters of the function it's scoped within. In other words, it doesn't work like that, it only refers to what exists inside Javascript and the Javascript file you're running:
function helloWorld() {
for (param of arguments) alert(param);
}
helloWorld("a", "b", "c");
// "a"
//
// "b"
//
// "c"
alert(arguments) // Always "Undefined" or length of 0, it doesn't exist in root/global scope in any meaningful way
You could write a batch file which would write these params to a temp file on Desktop then launch the extension and run the script which reads then parses that temp file to get the same result or a bin command for NodeJS to do something similar but as it stands the default behavior of shell has no bearing or relation to the scripting environment within the app.