Skip to main content
JennB_FL
Participant
Jan 23, 2025 12:28 AM UTC
Answered

Script not functioning in InDesign 2025

I have a script I've been using since 2010 that will not work with InDesign 2025. It saves the InDesign file to single page PDFs with the file name being the page number. I have no knowledge of scripts (only how to use them). Can anyone help diagnose what needs to change?

 

tell application "Adobe InDesign 2025"

set doc_name to active document

set doc_pages to every page of doc_name

set file_name to text returned of (display dialog "Please enter a File Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)

set pdf_style to name of every PDF export preset

set export_style to (choose from list pdf_style with prompt "Select PDF Export Preset") as string

set folder_path to (choose folder with prompt "Please select your destination folder...") as string

 

repeat with anItem in doc_pages

set page_number to name of anItem as string

count characters of page_number

if length of page_number is 1 then

set new_number to text -3 thru -1 of ("00" & page_number)

end if

if length of page_number is 2 then

set new_number to text -3 thru -1 of ("0" & page_number)

end if

if length of page_number is 3 then

set new_number to page_number

end if

if length of page_number is 4 then

set new_number to page_number

end if

set PDF_name to folder_path & file_name & "_" & new_number & ".pdf"

set page range of PDF export preferences to page_number

tell doc_name

export format PDF type to PDF_name using export_style without showing options

end tell

end repeat

 

beep 3

display dialog "Your PDFs were successfully exported" buttons {"Done"} default button 1

end tell

JennB_FL
JennB_FLCorrect answer
Participant
Jan 24, 2025 4:35 PM UTC

Ok cool - thanks for letting us know

 

do you mind sharing the updated code - it could help in the future 


Sure!

 

--Version 4.0  01/19/2022

--Version 5.0  10/30/2024

(* 

 

The following changes were made for ID 2025

 

tell doc_name

export format PDF type to PDF_name using export_style without showing options

-nd tell

 

TO

 

try

export doc_name format PDF type to file PDF_name using export_style without showing options

on error errMsg

display dialog "Error exporting PDF: " & errMsg buttons {"OK"} default button 1

end try

*)

 

--Version relies on Section prefix property turned out to be the key from v.25. 

--Without this Section prefix property change, the script did not pay attention to the "C" in front of the page numb

--changed section prefix from a looop to "set include section prevfix of *every section* in order to avoid counting

 

with timeout of 86400 seconds

tell application "Adobe InDesign 2025"

set doc_name to active document

set doc_pages to every page of doc_name

set thecount to count of pages of doc_name

repeat with i from 1 to thecount - 1

set include section prefix of every section of doc_name to true

end repeat

 

set file_name to text returned of (display dialog "Please enter a File Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon 1)

set pdf_style to name of every PDF export preset

set export_style to (choose from list pdf_style with prompt "Select PDF Export Preset") as string

set folder_path to (choose folder with prompt "Please select your destination folder...") as string

 

repeat with anItem in doc_pages

set page_number to name of anItem as string

count characters of page_number

if length of page_number is 1 then

set new_number to text -3 thru -1 of ("00" & page_number)

end if

if length of page_number is 2 then

set new_number to text -3 thru -1 of ("0" & page_number)

end if

if length of page_number is 3 then

set new_number to page_number

end if

if length of page_number is 4 then

set new_number to page_number

end if

set PDF_name to folder_path & new_number & "_" & file_name & ".pdf"

set page range of PDF export preferences to page_number

try

export doc_name format PDF type to file PDF_name using export_style without showing options

on error errMsg

display dialog "Error exporting PDF: " & errMsg buttons {"OK"} default button 1

end try

end repeat

 

beep 3

display dialog "Your PDFs were successfully exported" buttons {"Done"} default button 1

end tell

end timeout

4 replies

Community Expert
Jan 23, 2025 5:38 AM UTC

Looks like Apple Script not UXP

Try this

tell application "Adobe InDesign 2025"
    if not (exists active document) then
        display dialog "No document is currently open." buttons {"OK"} default button 1
        return
    end if

    set doc_name to active document
    set file_name to text returned of (display dialog "Please enter a File Name:" default answer "" buttons {"Cancel", "Ok"} default button 2 with icon caution)

    set pdf_style to name of every PDF export preset
    if pdf_style is {} then
        display dialog "No PDF export presets found." buttons {"OK"} default button 1
        return
    end if

    set export_style to (choose from list pdf_style with prompt "Select PDF Export Preset" without multiple selections allowed and empty selection allowed) as string
    if export_style is "false" then return

    set folder_path to POSIX path of (choose folder with prompt "Please select your destination folder...")

    set doc_pages to every page of doc_name
    repeat with anItem in doc_pages
        set page_number to name of anItem as string

        if (count of characters of page_number) is 1 then
            set new_number to "00" & page_number
        else if (count of characters of page_number) is 2 then
            set new_number to "0" & page_number
        else
            set new_number to page_number
        end if

        set PDF_name to folder_path & file_name & "_" & new_number & ".pdf"
        set page range of PDF export preferences to page_number
        export doc_name format PDF type to PDF_name using export style export_style without showing options
    end repeat

    beep 3
    display dialog "Your PDFs were successfully exported" buttons {"Done"} default button 1
end tell


 

Translate
JennB_FL
JennB_FLAuthor
Participant
Jan 24, 2025 2:11 PM UTC

Thank you so much for your help. After I posted, the original script-writer sent me a new one. I truly appreciate your help!

Translate
Community Expert
Jan 24, 2025 3:10 PM UTC

Ok cool - thanks for letting us know

 

do you mind sharing the updated code - it could help in the future 

Translate