6 Replies Latest reply on May 29, 2016 7:04 AM by eddiee1993

    Need help Scripting

    eddiee1993

         I am a beginner at scripting, coding, and web design. I have been having questions regarding scripting.

      I need help developing an Adobe Script that will 1)Automatically open a PDF file I have (created in Illustrator CC 2015)

                                                                                    2) Automatically change the name of two swatches,  to new names I have

                                                                                    3) Save with same file name plus "_Z.PDF" at the end

                                                                                     4) Then close the file.

        • 1. Re: Need help Scripting
          moluapple Level 4

          So you mean you've saved all your pdf file with "Preserve Illustrator Editing Capabilities" option checked on? You can start from here.

           

          // 1)
          var f = new File('path/to/filename.pdf');
          var doc = app.open(f);
          // 2)
          doc.swatches.getByName('swatch_1').name = 'new_swatch_1';
          doc.swatches.getByName('swatch_2').name = 'new_swatch_2';
          // 3)
          doc.saveAs(new File(f.fsName.replace(/\.pdf$/, '_Z.pdf')), new PDFSaveOptions());
          // 4)
          doc.close();
          
          • 2. Re: Need help Scripting
            eddiee1993 Level 1

            Thank you very much for your time and help. I tried running the script this way below but it says

            there is still an error in the part :  var doc = app.open(f);

            What should I do about this? I have it underlined below too in bold italics.

             

            function test()

            {

                // 1) 

             

                var thePath = "~/Desktop/";

                var theFile = "test_swatch_change.pdf";

                var f = new File(thePath + theFile); 

                var newFileName = theFile.replace(/\.pdf$/, "_Z.pdf");

               var doc = app.open(f);

                // 2) 

                doc.swatches.getByName('Kiss Cut').name = ('CutContourKiss-cut'); 

                doc.swatches.getByName('Through Cut').name = ('CutContourThru-cut'); 

                // 3) 

             

                var saveFile = new File(thePath + newFileName);

                var saveOpts = new PDFSaveOptions();

               

                doc.saveAs(saveFile, saveOpts); 

                // 4) 

                doc.close(); 

            }

            test();

            • 3. Re: Need help Scripting
              moluapple Level 4

              Just works fine here.

              try { var doc = app.open(f) } catch (e) { alert(e) }

              what's the error info?

              • 4. Re: Need help Scripting
                eddiee1993 Level 1

                It says its not a function. I think its app.open that they are referring too.

                • 5. Re: Need help Scripting
                  moluapple Level 4

                  Oh no, did you run it from ESTK and had not set target to illustrator?

                  • 6. Re: Need help Scripting
                    eddiee1993 Level 1

                    yes, it wasnt going through