Copy link to clipboard
Copied
Hello! So this is what I want to achieve in order to automate the prepress saving process:
1. I want to execute these functions:
app.executeMenuCommand("unlockAll");
app.executeMenuCommand("selectall");
app.executeMenuCommand("OffsetPath v22");
app.executeMenuCommand("outline");
2. And then to Save the file as a pdf in a relative location: "currentDocPath/Prepress/currentFileName.pdf" (the prepress folder should be created if it doesn't exist and the PDF file should be overwritten if there is already a PDF there.
P.S. the unlock all function unlocks the locked objects. Is there an action that I can place before it to unlock the layers so it doesn't miss some text object in a locked layer?
Thank you for your help!
2 Correct answers
Try this: (It appears the word "path" is reserved or something like that.)
var path1 = app.activeDocument.path;
var exportFolder = Folder(path1 + "/yourFolderName");
if (!exportFolder.exists){
exportFolder.create();
}
var file = new File(path1 + "/yourFolderName/yourFileName");
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file, PDF);
Thank you a million times! I added another snippet of code for embedding the linked files. So here is the final script:
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
layers[i].locked = false;
}
app.executeMenuCommand("unlockAll");
app.executeMenuCommand("selectall");
app.executeMenuCommand("OffsetPath v22");
app.executeMenuCommand("outline");
executeMenuCommand
// Embedding Action
if ( app.documents.length > 0 ) {
while ( app.activeDocument.placedItems
...
Explore related tutorials & articles
Copy link to clipboard
Copied
To unlock all layers:
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
layers[i].locked = false;
}
To create folder and file, respectively (note the absolute path as I am unfamiliar with relative paths):
var path1 = "/C/Users/Username/Desktop/yourFolderName/";
var folder1 = new Folder(path1);
folder1.create();
var file1 = new File(path1 + "yourFileName");
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
So presumably your script would look something like this:
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
layers[i].locked = false;
}
app.executeMenuCommand("unlockAll");
app.executeMenuCommand("selectall");
app.executeMenuCommand("OffsetPath v22");
app.executeMenuCommand("outline");
var path1 = "/C/Users/Username/Desktop/yourFolderName/";
var folder1 = new Folder(path1);
folder1.create();
var file1 = new File(path1 + "yourFileName");
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file1, PDF);
Copy link to clipboard
Copied
Thanks! I found this as an explanation for relative paths:
var path = app.activeDocument.path; var exportFolder = Folder(path + "/exports"); if(!exportFolder.exists){ exportFolder.create(); } var dest = exportFolder + "/testme.pdf";
I tried merging them with yours, but I am making a mistake somewhere:
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
layers[i].locked = false;
}
app.executeMenuCommand("unlockAll");
app.executeMenuCommand("selectall");
app.executeMenuCommand("OffsetPath v22");
app.executeMenuCommand("outline");
var path = app.activeDocument.path;
var exportFolder = Folder(path + "/exports");
if(!exportFolder.exists){
exportFolder.create();
}
var file = new File(path + "yourFileName");
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file, PDF);
Copy link to clipboard
Copied
Try this: (It appears the word "path" is reserved or something like that.)
var path1 = app.activeDocument.path;
var exportFolder = Folder(path1 + "/yourFolderName");
if (!exportFolder.exists){
exportFolder.create();
}
var file = new File(path1 + "/yourFolderName/yourFileName");
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file, PDF);
Copy link to clipboard
Copied
Thank you a million times! I added another snippet of code for embedding the linked files. So here is the final script:
var layers = app.activeDocument.layers;
for (var i = 0; i < layers.length; i++) {
layers[i].locked = false;
}
app.executeMenuCommand("unlockAll");
app.executeMenuCommand("selectall");
app.executeMenuCommand("OffsetPath v22");
app.executeMenuCommand("outline");
executeMenuCommand
// Embedding Action
if ( app.documents.length > 0 ) {
while ( app.activeDocument.placedItems.length > 0 ) {
placedArt = app.activeDocument.placedItems[0];
placedArt.embed();
}
}
// Change foldername1 according to your liking.
var foldername1 = "Prepress"
var path1 = app.activeDocument.path;
var filename1 = app.activeDocument.name;
var exportFolder = Folder(path1 + "/" + foldername1);
if (!exportFolder.exists){
exportFolder.create();
}
var file = new File(path1 + "/" + foldername1 + "/" + filename1);
var PDF = new PDFSaveOptions;
app.activeDocument.saveAs(file, PDF);

