Skip to main content
May 20, 2010
Question

Running applescript on multiple Indesign documents

  • May 20, 2010
  • 2 replies
  • 4579 views

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

This topic has been closed for replies.

2 replies

Kathlene Sage
Known Participant
May 20, 2010

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.

Kasyan Servetsky
Legend
May 20, 2010

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

Participant
April 5, 2011

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

Muppet_Mark-QAl63s
Inspiring
April 5, 2011

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