Skip navigation
maxrus2012
Currently Being Moderated

Help with script to make PDFs

Jul 16, 2012 12:35 AM

Tags: #cs5.5 #indesign #applescript #automation

Hi

I have an Applescript that will pdf an indesign file but I want to improve it.

I want it to be a droplet that can process multiple files.

Here is the script and thanks in advance to anyone who can help.

 

    tell application "Adobe InDesign CS5.5"

        set user interaction level of script preferences to never interact

        activate

        set My_Pdf_Presets to name of every PDF export preset

        set MyPdfPreset to choose from list My_Pdf_Presets with prompt "Choose a preset"

        if MyPdfPreset is false then

            display dialog "User Cancelled!" buttons "OK" giving up after 60

            error number -128

        end if

       

        set properties of PDF export preferences to properties of PDF export preset (item 1 of MyPdfPreset)

        set page range of PDF export preferences to all pages

        set MyFolder to file path of active document

       

        tell application "Finder"

            if (exists folder "PDFs" of folder MyFolder) is false then

                make new folder at MyFolder with properties {name:"PDFs"}

            end if

        end tell

       

        set MyDocName to name of active document

        set OrigDelims to text item delimiters of AppleScript

        set text item delimiters of AppleScript to {"."}

        set MyShortName to text item 1 of MyDocName

        set text item delimiters of AppleScript to OrigDelims

        set MyFilePath to MyFolder & "PDFs" & ":" & MyShortName & ".pdf" as string

       

        tell active document

            export format PDF type to MyFilePath without showing options

            close saving no

        end tell

        set user interaction level of script preferences to interact with all

        activate

        display dialog "Your PDFs are ready" with icon 1 buttons {"OK"} default button "OK"

    end tell

 
Replies
  • Currently Being Moderated
    Jul 16, 2012 1:56 AM   in reply to maxrus2012
     
    |
    Mark as:
  • Currently Being Moderated
    Jul 17, 2012 11:14 AM   in reply to maxrus2012

    Third day raining nonstopp ;-)

     

    So, try this:

     

     

     

    (*Has to be saved as programm …

    Works with folders and files dropped onto

     

    Tested with ID CS 5.5; OSX 10.7.4

    *)

     

    property pdfPreset : ""

    property counter : 0

    property errorsOccurred : 0

     

     

    on open these_items

    set counter to 0

    set errorsOccurred to 0

        --get pdf export preset

        set pdfPreset to getExportPreset()

        if pdfPreset is false then

            activate

            display alert "No PDF-Preset selected."

        else

            --loop    

            repeat with i from 1 to the count of these_items

                set this_item to (item i of these_items)

    --'info for' should be replaced in future but for now it's easy to use ...

                set the item_info to info for this_item

                if folder of the item_info is true then

                    process_folder(this_item)

                else

                    set {fileContainer, shortName} to my getContainer(this_item)

                    process_item(this_item as text, fileContainer, shortName, pdfPreset)

                end if

            end repeat

            activate

            display dialog "Finished. | " & counter & " files have been exported. | " & errorsOccurred & " Errors occurred."

        end if

    end open

     

    on process_folder(this_folder)

        set these_items to list folder this_folder without invisibles

        repeat with i from 1 to the count of these_items

            set this_item to alias ((this_folder as text) & (item i of these_items))

            set the item_info to info for this_item

            if folder of the item_info is true then

                process_folder(this_item)

            else

                set {fileContainer, shortName} to my getContainer(this_item)

                process_item(this_item as text, fileContainer, shortName, pdfPreset)

            end if

        end repeat

    end process_folder

     

    --get folder and short filename (without possible extension)

    on getContainer(this_item)

        set TID to AppleScript's text item delimiters

     

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

        set folderPath to ((text items 1 thru -2 of (this_item as string)) as text) & ":"

        set trimmedName to text item -1 of (this_item as string)

     

        if trimmedName contains "." then

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

            set trimmedName to text 1 thru text item -2 of trimmedName

        end if

     

        set AppleScript's text item delimiters to TID

     

        return {folderPath, trimmedName}

    end getContainer

     

    on getExportPreset()

        tell application "Adobe InDesign CS5.5"

            set My_Pdf_Presets to name of every PDF export preset

     

            set MyPdfPreset to (choose from list My_Pdf_Presets with prompt "Choose a preset to process the dropped files" without multiple selections allowed)

     

            if MyPdfPreset is false then

                return false

            else

                return item 1 of MyPdfPreset

            end if

     

        end tell

    end getExportPreset

     

    on process_item(this_item, fileContainer, shortName, pdfPreset)

        do shell script "mkdir -p " & quoted form of POSIX path of (fileContainer & "PDFs")

        try

            tell application "Adobe InDesign CS5.5"

                set myDoc to open alias this_item

                set pdfFilePath to fileContainer & "PDFs" & ":" & shortName & ".pdf" as string

                set page range of PDF export preferences to all pages

                set chosedPdfPreset to PDF export preset pdfPreset

                export myDoc format PDF type to pdfFilePath using chosedPdfPreset without showing options

     

                close myDoc saving no

                set counter to counter + 1

     

            end tell

        on error e

            set errorsOccurred to errorsOccurred + 1

            display dialog "My problem: " & e giving up after 3

        end try

    end process_item

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points