3 Replies Latest reply on Nov 16, 2017 1:14 AM by philt66306057

    Illustrator CC Script - Save to folder destination


      I've found a Illustrator cc script that i've adapted and added to make my life 5 times easier. To make it 6 times easier i'd love to save it to a destination folder chosen in the diaglog box at the start. For the life of me I can't work out what to do. Everything I try using " Folder.selectDialog" either saves it in the folders current location or in recent location.

      What the current script does is:

      Saves .ai file out as 3 separate files based on some presets with the following extentions .ai OL.pdf and OL_LR.pdf

      #target illustrator
      #targetengine "main"
      for (x=0;x<app.documents.length;x++)
           var workingDoc = app.documents[x];
           var workingDocFile = workingDoc.fullName;
           var HighPreset = 'High Res';
           var LowPreset = 'Low Res';
      // populate these with your settings
           var aiFile = new File(workingDocFile.toString().replace(".ai","_OL.ai"));    
           var lowResOpts = new PDFSaveOptions();
           var highResOpts = new PDFSaveOptions();
           var lowResFile = new File(workingDocFile.toString().replace(".ai","_OL_LR.pdf"));
           var highResFile = new File(workingDocFile.toString().replace(".ai","_OL.pdf"));


      Any help would be much appreciated.

      Thanks, Phil

        • 1. Re: Illustrator CC Script - Save to folder destination
          daneJ Level 1

          Hi Phil

          Making PDFs seams like shooting in the dark. my codes work today or in this minute and then dont tomorrow or in the next minute.

          anyway I use: saveName = workingDoc.path.fsName rather than: .fullName.

          This works for me.

          Also I am not so fancy with the .replace() so I just write saveName =  saveName + "something". I am not saying this is elegent but maybe it is safer?




          • 2. Re: Illustrator CC Script - Save to folder destination
            williamadowling Level 4


            the .replace() function used in the example does something different than your example of

            saveName =  saveName + "something"

            in your example, if saveName was already "myFile.ai", your code would result in "myFile.ai.something". the regex replace() function actually changes a part of the given string if necessary. I don't think there's anything "dangerous" about using replace over standard string concatenation. they are simply different. in fact one might argue that regular concatenation COULD be more dangerous because it will always change the resulting string even if you didn't want to..

            • 3. Re: Illustrator CC Script - Save to folder destination
              philt66306057 Level 1

              Thanks for the replys! I managed to work something out in the end and simplified it a bit. Heres the code incase anyone else needs it.


              #target illustrator 

              function PDFSaver(){ 

                var doc = app.activeDocument;

                var destFolder = Folder(app.activeDocument.path).selectDlg('Select the folder where you want to save the PDF files.'); 

                var LowResopts = new PDFSaveOptions();

                var HighResopts = new PDFSaveOptions(); 

                LowResopts.pDFPreset = "Low Res";

                HighResopts.pDFPreset = "High Res"; 


                doc.saveAs(File(destFolder + "/" + doc.name.replace(".ai", "_OL.ai"))); 

                doc.saveAs(File(destFolder + "/" + doc.name.replace("_OL.ai", "_OL.pdf")), HighResopts);

                doc.saveAs(File(destFolder + "/" + doc.name.replace("_OL.pdf", "_OL_LR.pdf")), LowResopts); 



                alert( 'Action Completed Succesfully, Yayyyy! Files saved in ' + destFolder );






              I also combined this into an action with illustrator so it outlines all text then runs this script by pressing a hot key. My life is now 7 times easier!