Copy link to clipboard
Copied
I'm having an issue with saving a file and I can't tell why it's not working. This is original code. I believe I'm commenting out the variables incorrectly or i'm incorrectly using adobe syntax. Any help would be greatly appreciated, this helps automate cross-application workflows.
part that is broken:
,app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";
Full script (runs action in photoshop on a psd, then runs action in illustrator to open an eps. Is supposed to save the file in illustrator to the same directory as the psd)
#target photoshop
//run action in photoshop
app.doAction ("action name", "action set name");
//get path of the open document
var psdpath = activeDocument.path.fsName;
//get directory name of psd, to use in filename later
var parentdirectory = activeDocument.path.name;
//start bridgetalk
var bt = new BridgeTalk;
//targets version 25. v26 crashes if window isnt active at run
bt.target = "illustrator-25";
//run action in illustrator (which opens an eps w/linked file and performs certain tasks) and then save the document
var script = "app.doScript('action name', 'action set name'),app.activeDocument.saveAs(File('"+psdpath+"'/' + doc.name.replace('PLACEHOLDER', '"+parentdirectory+"'))";
//the entire action must be within double quotes, eg:
// var script = alert("test", "this sends alert to photoshop");
// var script = "alert('test', 'this sends alert to illustrator'),alert('"+psdpath+"', '"+psdpath+"')"; //psdpath is properly sent to illustrator
bt.body = script;
bt.send();
Make a string script like this:
var strScript = """
var doc = app.open(File("%1"));
alert("Illustrator document: " + doc.name);
""";
var editedScript = strScript.replace("%1", "~/Desktop/test.ai");
var bt = new BridgeTalk();
bt.target = "illustrator";
bt.body = editedScript;
bt.onResult = bt.onError = function (res) {
alert(res.body);
}
bt.send();
Now you can edit the script string and the replacement operations to construct the Illustrator script how you like it.
Nvm I figured it out. Sorry i'm not super skilled w/js
use %1 and %2 etc in the script string, and then replace w/variables on editedScript variable.
works perfect. you can now drag and drop psd files onto a droplet shortcut (or use an adaptation of a hot folder from a project i put together) and it will run photoshop action, open illustrator, run illustrator action and then save as an eps in the same directory of the photoshop file.
#target photoshop
app.doAction ("ps action name", "ps action se
...
Copy link to clipboard
Copied
Make a string script like this:
var strScript = """
var doc = app.open(File("%1"));
alert("Illustrator document: " + doc.name);
""";
var editedScript = strScript.replace("%1", "~/Desktop/test.ai");
var bt = new BridgeTalk();
bt.target = "illustrator";
bt.body = editedScript;
bt.onResult = bt.onError = function (res) {
alert(res.body);
}
bt.send();
Now you can edit the script string and the replacement operations to construct the Illustrator script how you like it.
Copy link to clipboard
Copied
@Silly-V , thank you very much for your response. Since you replied, I've tried string replacement from various angles am having difficulties with the output / configuration of the string replacement. If you could point me in the direction of how to either troubleshoot or plainly fix it altogether please let me know. Also I was able to fix illustrator crashing by bringing to front first.
I am very grateful for any direction or solution.
#target photoshop
var psdpath = activeDocument.path.fsName;
var parentdirectory = activeDocument.path.name;
app.doAction ("Photoshop Action Name", "Photoshop action Set");
var strScript = """
app.doScript("Illustrator Action Name", "Illustrator Action Set");
var doc = app.activeDocument;
if (documents.length > 0){
var saveOpts = new EPSSaveOptions();
saveOpts.embedLinkedFiles = embedImage = false;
saveOpts.embedAllFonts = embedFont = true;
saveOpts.includeDocumentThumbnails = false;
saveOpts.saveMultipleArtboards = false;
fullDocName = doc.fullName;
for (i=0; i<doc.layers.length; i++){
if (i-1<0) doc.layers[i].visible = true;
else {
doc.layers[i-1].visible = false;
doc.layers[i].visible = true;
}
if (doc.layers[i].locked == false) {
docName = doc.layers[i].name+".eps";
var saveName = new File ( psdpathh + "/" + parentdirectoryy + ".eps");
doc.saveAs( saveName, saveOpts );
}
}
}
""";
var editedScript = strScript.replace("psdpathh", psdpath); // this is a remnant test, it does not work
var editedScript2 = editedScript.replace("parentdirectoryy", parentdirectory); // this is a remnant test, it does not work
BridgeTalk.bringToFront("illustrator");
var bt = new BridgeTalk;
bt.target = "illustrator-25";
bt.body = editedScript2;
bt.send();
Copy link to clipboard
Copied
Nvm I figured it out. Sorry i'm not super skilled w/js
use %1 and %2 etc in the script string, and then replace w/variables on editedScript variable.
works perfect. you can now drag and drop psd files onto a droplet shortcut (or use an adaptation of a hot folder from a project i put together) and it will run photoshop action, open illustrator, run illustrator action and then save as an eps in the same directory of the photoshop file.
#target photoshop
app.doAction ("ps action name", "ps action set"); //replace w your action details
var psdpath = activeDocument.path.fsName;
var parentdirectory = activeDocument.path.name;
var strScript = """
app.doScript("illustrator action name", "illustrator action set"); //replace w your action details
var doc = app.activeDocument;
if (documents.length > 0){
// Create the illusrtratorSaveOptions object to set the AI options
var saveOpts = new EPSSaveOptions();
// Setting IllustratorSaveOptions properties.
saveOpts.embedLinkedFiles = embedImage = true;
saveOpts.embedAllFonts = embedFont = true;
saveOpts.includeDocumentThumbnails = true;
saveOpts.saveMultipleArtboards = false;
fullDocName = doc.fullName;
for (i=0; i<doc.layers.length; i++){
if (i-1<0) doc.layers[i].visible = true;
else {
doc.layers[i-1].visible = false;
doc.layers[i].visible = true;
}
if (doc.layers[i].locked == false) {
docName = doc.layers[i].name+".eps";
var saveName = new File ( "%1/%2 -- suffix.eps"); //replace " -- suffix" to whatever, keep .eps
doc.saveAs( saveName, saveOpts );
}
}
}
""";
var editedScript = strScript.replace("%1", psdpath).replace("%2", parentdirectory);
BridgeTalk.bringToFront("illustrator-25"); // switch view to illustrator to prevent crashing
var bt = new BridgeTalk;
//declare your illustrator version
bt.target = "illustrator-25";
bt.body = editedScript;
bt.send();