8 Replies Latest reply on Apr 6, 2011 3:12 PM by Muppet Mark-QAl63s

    Running applescript on multiple Indesign documents

    Dawid_Ruzicka Level 1

      Hello all,

       

      I was wondering if anyone knows how to run an applescript on multiple documents. Lets say I have ten INdd CS4 documents in a folder. I would like to open one , run my AS script, save and close, open next.... etc.

       

      Maybe something like this already exists. any idea or suggestion would be very helpful.

       

      thank you very much

       

      Dawid

        • 1. Re: Running applescript on multiple Indesign documents
          Kasyan Servetsky Level 5

          Hi Dawid,

           

          Here is an example:

          tell application "Finder"
               set myInFolder to choose folder with prompt "Select a folder"
               set myFilelist to files in myInFolder whose name ends with ".indd"
          end tell
          
          tell application "Adobe InDesign CS3"
               set user interaction level of script preferences to never interact
               repeat with myDoc from (count myFilelist) to 1 by -1
                    set myCurrentFile to item myDoc of myFilelist
                    open myCurrentFile
                    set myCurDocument to active document
                    tell myCurDocument
          
                         -- do your staff here
          
                         close saving yes -- save and close
                    end tell
               end repeat
               set user interaction level of script preferences to interact with all
               beep 3
               display alert "Finished!"
          end tell
          

           

          Hope this helps.

           

          Kasyan

          • 2. Re: Running applescript on multiple Indesign documents
            Kathlene Ruhan Level 3

            With applescript, you can write one script and save it as an app - then drag and drop all your files at once onto the script and let them fly. Or you can open the script and have it prompt you for the file name as each one completes. I'm not too familiar with JS though - perhaps the same can be done.

            • 3. Re: Running applescript on multiple Indesign documents
              Terje Gunnesmæl Level 1

              Hi you others in this tread!

              First of all let me thank you for your postings. They`ve been to great help.

              Still I`m not getting it "right" on my own.

               

              I run this on a relatively new iMac with the Adobe Creative Suite CS5

               

              Firstly let me show you my script so far:

              ---------------------------------------------------------

              tell application "Finder"
                  set myInFolder to choose folder with prompt "Select a folder"
                  set myFilelist to files in myInFolder whose name ends with ".indd"
              end tell

               

              tell application "Adobe InDesign CS5"
                  set user interaction level of script preferences to never interact
                  repeat with myDoc from (count myFilelist) to 1 by -1
                      set myCurrentFile to item myDoc of myFilelist
                      open myCurrentFile
                      set myCurDocument to active document
                      tell myCurDocument
                         
                          set Doc_Name to name
                         
                          export format PDF type to "Macintosh HD:Users:smael:Desktop:out:" & Doc_Name & ".pdf" without showing options
                         
                          close saving yes -- save and close
                      end tell
                  end repeat
                  set user interaction level of script preferences to interact with all
                  beep 3
                  display alert "Finished!"
              end tell

              ---------------------------------------------------------

               

              For some reason it doesn`t work 100%.

              • Most important it doesn`t process all indesign files in a folder. Just the first one...
              • When I set the code for filenaming it takes the extension as well mydocument.indd.pdf

               

              What I would like to do

              • process all .indd in the folder prompted
              • bring along the filename, include .trykk and finally the extension .pdf (exmpl: take the file "harrypotter.indd" resulting in "harrypotter.trykk.pdf")
              • To export it with a spesific preset, let`s say "smallest file size"
              • a new prompt where I can create a new folder at a chosen location, name it and put all the outputfiles inside it

               

              Too much to ask for maybe?

              I`m totally new to "programing" so all help is appreciated!

               

              Regards

              Terje

              • 4. Re: Running applescript on multiple Indesign documents
                Muppet Mark-QAl63s Level 4

                This did what you wanted with the briefest of tests…

                 

                set InputFolder to choose folder with prompt "Select an input folder"

                 

                tell application "Finder"

                set IDFileList to every file of InputFolder whose name ends with ".indd"

                set IDcount to count of IDFileList

                end tell

                log IDcount

                 

                if IDcount > 0 then

                set OuputFolder to choose folder with prompt "Select an output folder"

                tell application "Adobe InDesign CS5"

                activate

                set user interaction level of script preferences to never interact

                repeat with i from 1 to IDcount

                open (item i of IDFileList)

                set DocRef to the active document

                tell DocRef

                set DocName to name

                set DocName to text 1 thru -6 of DocName

                log DocName

                set SaveName to DocName & ".trykk.pdf"

                set SavePath to (OuputFolder as text) & SaveName

                export format PDF type to SavePath ¬

                using "[Smallest File Size]" without showing options

                close saving yes

                end tell

                end repeat

                set user interaction level of script preferences to interact with all

                beep 3

                display alert "Finished!" giving up after 3

                end tell

                else

                display dialog "Nothing to process?" giving up after 3

                end if

                • 5. Re: Running applescript on multiple Indesign documents
                  Terje Gunnesmæl Level 1

                  Wow!!

                  ;o)

                  That made my day!

                   

                  The only "bug" is that it still only processes one inDesign file, even when the folder contains several inDesign files.

                  And there`s no alerts as well (finished), from what I could tell from the script, that it should be.

                  Any idea?

                   

                  Regards Terje

                  • 6. Re: Running applescript on multiple Indesign documents
                    Muppet Mark-QAl63s Level 4

                    I think that's the first time I've tried use AppleScript with CS5. A couple of things I noticed. I could not reduce the text of the name until I'd first set it to a variable can't see why should just be a string… When I first ran on a bunch of files including older CS2 ones it stopped at the second claiming that the 'user had canceled' which I ain't touched nothing… Tested with just new CS5 files and no problems… I have not had the time to check but there may be some opening options required for use with older files… In one or two places I did include 'log' so you can see the values of variables displayed in the event log… you can remove these they are not needed… What is the last report in your event log…?

                    • 7. Re: Running applescript on multiple Indesign documents
                      Terje Gunnesmæl Level 1

                      Hi!

                      I tested it on a second iMac and it worked wonderfully!

                      I guess I have some sort of bug in my machine or during installation of CS5.

                       

                      I have a few other ideas with that script, so I`m eager to begin  ;o)

                       

                      Thanks again!

                      Terje

                      • 8. Re: Running applescript on multiple Indesign documents
                        Muppet Mark-QAl63s Level 4

                        If you found this thread via a web/forum search and are new to scripting… Then consider your choice of language… On your OS you can go with AppleScript or use Adobe's ESTK (javascript based) language. There are pros and cons to each. You will certainly get more help in this forum with the latter. Either way have fun… Glad you got it working anyhow…