4 Replies Latest reply on Nov 12, 2015 5:15 AM by rickg76305781

    SAVE-PDF-UPLOAD applescript help??

    rickg76305781

      i have script for MultiAd Creator Pro that i helped develop ...it uploads a pdf file to select volume/folder when the user saves a document...I would like to do the same in Indesign

       

      so ...the user saves the doc. and is then prompted yes/no save the "Send Proof"? if yes then... the script uploads a PDF to a select destination. The script defines the the static destination, PDF criteria and also does name modification.

       

      below is the Creator script (it is placed in Creator Attached Scripts folder)

       

      property PDFPath : "PDFProofs:"

       

      using terms from application "MultiAd Creator Pro"

          on saved theDoc

              set question to display dialog "Send Proof?" buttons {"Yes", "No"} default button 2

              set answer to button returned of question

              if answer is "Yes" then

                  set fileName to name of theDoc

                  set destFolder to PDFPath

                

                

                  --Trim off .crtr extension if it has one:

                  if fileName ends with ".crtr" then

                      set sd to AppleScript's text item delimiters

                      set AppleScript's text item delimiters to {"."}

                      set fileName to (text items 1 thru -2 of fileName) as text

                      set AppleScript's text item delimiters to sd

                  end if

                

                

                  tell application "MultiAd Creator Pro"

                    

                      export PDF current spread of theDoc saving in (destFolder & fileName & ".pdf") print order user order export method composite output color space CMYK stand in resolution 300 black and white compression use zip color image compression use JPEG quality 80 with embed no base 14 fonts, use doc size, binary encoding and compress text and line art without print as spreads, crop marks, registration marks, color bars, document notes, plate information, text blocks only and presentation mode

                  end tell

                

                  tell application "Finder"

                      activate

                      tell application "MultiAd Creator Pro"

                          activate

                      end tell

                  end tell

              end if

          end saved

      end using terms from

       

       

       

       

      .............

       

      IMO the script is fairly straightforward but i am sure InDesign does things differently and  I am not sure how to convert it into an Indesign script...not to mention how i would get it to work on save with minimal interaction?

       

      plus i don't know how to capture the "export PDF" information (i.e. the preset PDF criteria) from Indesign. Perhaps this is something that could be preset and selected via prompt??

       

      any help would be greatly appreciated. thank you in advance rick

        • 1. Re: SAVE-PDF-UPLOAD applescript help??
          Stephen_A_Marsh Adobe Community Professional

          Not sure where I got this one from…

           

          pdf_export.jsx

           

           

          #target indesign;
          
          
          //~ try {export_to_pdf (app.books.item (get_book ()))}
          //~     catch (e) {alert (e.message + "\r(line " + e.line + ")")};
          
          
          var item = get_item ();
          var params = get_params (item);
          export_to_pdf (item, params)
          
          
          
          
          function export_to_pdf (item, params)
              {
              var pdf_export_settings = app.pdfExportPreferences.properties;
              app.pdfExportPreferences.viewPDF = params.view;
              item.exportFile (ExportFormat.pdfType, File (params.name), false, app.pdfExportPresets.item (params.preset));
              app.pdfExportPreferences.properties = pdf_export_settings;
              }
          
          
          
          
          function get_params (b)
              {
              var app_presets = app.pdfExportPresets.everyItem().name;
              var w = new Window ("dialog", "Export PDF", undefined, {closeButton: false})
              w.alignChildren = "right";
              w.main = w.add ("panel");
                  w.main.alignChildren = "left";
                  w.main.name = w.main.add ("group");
                      w.main.name.prompt = w.main.name.add ("statictext", undefined, "PDF name:");
                          w.main.name.prompt.preferredSize.width = 60;
                      var pdf_name = w.main.name.add ("edittext", undefined, b.extractLabel ("name") || decodeURI(String(b.fullName)).replace (/\.ind[db]$/, ".pdf"));
                          pdf_name.characters = 40;
                          pdf_name.active = true;
                  w.main.pr = w.main.add ("group");
                      w.main.pr.prompt = w.main.pr.add ("statictext", undefined, "Preset:");
                      w.main.pr.prompt.preferredSize.width = 60;
                      var presets = w.main.pr.add ("dropdownlist", undefined, app_presets);
                      presets.selection = presets.find (b.extractLabel ("preset")) || 0;
                  var view = w.main.add ("checkbox", undefined, "\u00A0View PDF after export");
                      view.value = b.extractLabel ("view");
              w.buttons = w.add ("group");
                  w.buttons.add ("button", undefined, "OK", {name: "ok"});
                  w.buttons.add ("button", undefined, "Cancel", {name: "cancel"});
              if (w.show() == 1)
                  {
                  b.insertLabel ("preset", presets.selection.text);
                  b.insertLabel ("name", pdf_name.text);
                  b.insertLabel ("view", String (view.value));
                  w.close();
                  return {name: pdf_name.text, preset: presets.selection.text, view: view.value}
                  }
              else
                  {w.close(); exit ()}
              }
                     
          
          
          function get_item ()
              {
              if (app.documents.length > 0)
                  {
                  // If .fullName fails the documents has never been saved and we can't do anything with it.
                  try {app.documents[0].fullName; return app.documents[0]}
                  catch (_) {exit ()};
                  }
              else
                  {
                  switch (app.books.length)
                      {
                      case 0: alert ("Please open a document or a book."); exit ();
                      case 1: return app.books[0];
                      default: return pick_book ();
                      }
                  }
              }
          
          
          
          
          function pick_book ()
              {
              var w = new Window ("dialog", "Select a book");
              w.alignChildren = "right";
              var g = w.add ("group");
                  var list = g.add ("listbox", undefined, app.books.everyItem().name);
                  list.minimumSize.width = 250;
                  list.selection = 0;
              var b = w.add ("group");
                  b.add ("button", undefined, "OK", {name: "ok"})
                  b.add ("button", undefined, "Cancel", {name: "cancel"})
              if (w.show () == 1)
                  return app.books.item (list.selection.text);
              else
                  exit ();
              }
          
          
          • 3. Re: SAVE-PDF-UPLOAD applescript help??
            rickg76305781 Level 1

            thank you stephen....i did see the link above..but i am not a JavaScripter.....so i wasn't sure how to modify it?

             

            if i read the script correctly..the user sets two presets conditions..and is prompted to pick one of the two presets. when the user picks it takes the file name (mDocName) and adds _PRINT.PDF or _WEB.PDF depending on the user selection. Am I correct??

             

            I am not sure where it defines the destination/path

             

            I will try to comply and run and see what it does lol

             

            R

             

             

             

             

            1. d = app.activeDocument;    
            2. preset1 = app.pdfExportPresets.itemByName("Hubcast Ready-Press Quality");    
            3. preset2 = app.pdfExportPresets.itemByName("Web-Ready (JPEG High 200dpi - No Color Conversion)");        
            4. if (!(preset1.isValid && preset2.isValid)){    
            5.     alert("One of the presets does not exist. Please check spelling carefully.");    
            6.     exit();    
            7. }  
            8.  
            9. mDocName = d.name.substr (0, d.name.lastIndexOf('.')); 
            10. mSourcePath = d.fullName.parent.toString(); 
            11. mRootPath =mSourcePath.substr (0, mSourcePath.lastIndexOf('/')); 
            12. mTargetPath=mRootPath.concat('/final/'); 
            13.  
            14. mNamePrint = mTargetPath.concat(mDocName,'_PRINT.pdf');    
            15. mNameWeb= mTargetPath.concat(mDocName,'_WEB.pdf'); 
            16.  
            17. if (!d.saved){    
            18.     d.save; 
            19. }     
            20.  
            21. d.exportFile(ExportFormat.PDF_TYPE, new File(mNamePrint), false, preset1);    
            22. d.exportFile(ExportFormat.PDF_TYPE, new File(mNameWeb), false, preset2);   
            • 4. Re: SAVE-PDF-UPLOAD applescript help??
              rickg76305781 Level 1

              the first script you posted does create a pdf to the desktop (where my orginal doc resides) i need to figure out where the path is defined. the path of my export will be static location...specifically "PDFProofs".