Copy link to clipboard
Copied
Hello,
i want to add to following script a default save folder location.
Any idea how?
( the default location i want to use is a network folder, \\SERVER2\customer requests\orders)
"function saveAsPDF() {
var pdfFile = new File(app.activeDocument.path + "/" + app.activeDocument.name.split('.')[0] + '.pdf');
var pdfOptions = new PDFSaveOptions();
pdfOptions.compatibility = PDFCompatibility.ACROBAT5;
pdfOptions.generateThumbnails = true;
pdfOptions.preserveEditability = false;
pdfOptions.preset = "[Smallest File Size]";
app.activeDocument.saveAs(pdfFile, pdfOptions);
}
saveAsPDF()"
Copy link to clipboard
Copied
Hi simosp,
here are some snippets I took from a much more complicated project of mine, hope you could use some of that.
These snippets will not work alone!!!
Keep in Mind that you need a swtich for Windows of MacOS
if($.os.match("Windows")) {
//Paths Windows Netzwerk
var path1 = "//Windows/path1/deeper"; //Windows
}
else {
//Paths MacOS Netzwerk
var path1 = "MacOS/path1/deeper"; //MacOS
}
---
//saveAS PDF
function exportFileToPdf(fileNameOnlyID, pathPdf, pdfPresetName) {
if (Folder(pathPdf).exists) {
var compPath = pathPdf + "/" + fileNameOnlyID + ".pdf";
var pdfPathPlusName = new File(compPath);
if (!pdfPathPlusName.exists) {
doc.saveAs(pdfPathPlusName, pdfPresetName);
} else {
var res = confirm("Die PDF-Datei existiert bereits hier:\r" + compPath + "\rSoll sie überschrieben werden?", true, "Problem");
// if the user hits no, move on without saving this
if (res !== true) {
return; //get out of this function
} else {
doc.saveAs(pdfPathPlusName, pdfPresetName);
}
}
} else {
alert("Ein oder mehrere Ordner existieren nicht. \rFunktion: pdf");
}
}
exportFileToPdf(fileNameOnlyID, path1, PDFX1);
Copy link to clipboard
Copied
//to set a default folder path
var mySaveFolderPath = "/SERVER2/customer requests/orders/";
//to get a save dialog that defaults to the above folder:
//if you don't want the dialog at all and you always want to save
//directly into the orders folder, just comment this line out.
mySaveFolderPath = Folder.selectDialog("Choose save folder", mySaveFolderPath);
//set the new file name to the save folder path + name of document
//and setup pdf save options
var saveFile = File(mySaveFolderPath + app.activeDocument.name.replace(/^\.(ai)|(svg)|(eps)/i,".pdf");
var pdfSaveOpts = new PDFSaveOptions();
pdfSaveOpts.compatibility = PDFCompatibility.ACROBAT5;
pdfSaveOpts.generateThumbnails = true;
pdfSaveOpts.preserveEditability = false;
pdfSaveOpts.preset = "[Smallest File Size]";
//save the file
app.activeDocument.saveAs(saveFile,pdfSaveOpts)
Copy link to clipboard
Copied
Copy link to clipboard
Copied
I think to get the Ai native saver you have to use a dynamic action, and also make sure it is set to show the dialog.
Otherwise, there's one small edit to @Disposition_Dev 's code which will still use the pathetic tiny Windows file-saver but will take you there:
var mySaveFolderPath = "/SERVER2/customer requests/orders/";
var possibleFile = File(mySaveFolderPath + "/test.pdf");
var saveLocation = possibleFile.saveDlg("Save the file");
// should take you right to that folder with the name "test.pdf" already pre-filled.
if (!saveLocation) {
alert("User cancelled saving op.");
}
Copy link to clipboard
Copied
Hello,
script is fine now, thank you!