Tuesday, September 2, 2014

Applescript to save InDesign pages as outlined EPS files

Today I wrote an Applescript that saves InDesign pages as EPS files, with text converted to outlines. It's kind of sad that I have to do this, but unfortunately that's where we are at this point. Anyway, I thought somebody might find this useful.

To use it, open up Applescript Editor and save as an application.

If you double-click on the application it will take the current InDesign document and:

  1. create a new subfolder inside the folder where the InDesign document is, called “PRINT”
  2. save the InDesign document as a “High Quality Print” PDF in that folder
  3. Open each page of the PDF in Illustrator, in turn, and then save it as an outlined EPS, in the same subfolder.

If you drag one or more closed InDesign files to the application icon, it will open each file in InDesign, do the above steps, and then close the document.

Here's the script...

on SaveAsEPS(indd)
    set thePrintDirName to "PRINT"
    tell application id "com.adobe.InDesign"
        set inddFolder to file path of indd
        set inddName to name of indd
    end tell
    -- the following sets basename to be the InDesign filename 
    -- without the .indd extension
    set AppleScript's text item delimiters to "."
    set TextItms to text items of inddName
    set LastItem to item -1 of TextItms
    if LastItem = "indd" then
        set TextItms to reverse of rest of reverse of TextItms
    end if
    set basename to (TextItms as string)
    set AppleScript's text item delimiters to ""
    -- make a PRINT folder underneath the InDesign file's folder
    tell application "Finder"
        if (exists folder thePrintDirName of folder inddFolder) is false then
            make folder at inddFolder with properties {name:thePrintDirName}
        end if
    end tell
    tell application id "com.adobe.InDesign"
        set theFileName to (inddFolder & thePrintDirName & ":" & basename) ¬
                    as string
        set thePDFName to (theFileName & ".pdf") as string
        tell PDF export preferences
            set page range to all pages
        end tell
        tell indd
            export format PDF type to thePDFName without showing options
        end tell
        set pageCount to count of pages of indd
        tell application "Adobe Illustrator"
            repeat with thePageNum from 1 to pageCount
                set user interaction level to never interact
                set page of PDF file options of settings to thePageNum
                open (thePDFName as alias) without dialogs
                set theEPSName to ¬
                     (theFileName & "_" & thePageNum & "_outl.eps") as string
                convert to paths text frames of current document
                save current document in (theEPSName) as eps ¬
                      with options {CMYK PostScript:true, ¬
                      embed all fonts:true, preview:color TIFF, ¬
                      compatibility:Illustrator 8}
                close current document saving no
            end repeat
        end tell
        display alert "Done exporting." giving up after 10
    end tell
end SaveAsEPS

on run {}
    tell application id "com.adobe.InDesign"
        set theInDD to active document
        tell me to SaveAsEPS(theInDD)
    end tell
end run

on open Lst
    tell application id "com.adobe.InDesign"
        repeat with zItm in Lst
            set Itm to zItm as alias
            set theInDD to open Itm
            tell me to SaveAsEPS(theInDD)
            close theInDD saving no
        end repeat
    end tell
end open

Good luck. Some of this was inspired by code on macgrunt.

No comments:

Post a Comment