Question
Here's an Applescript to increase every number by 1 (for static references, etc.)
Hope someone else benefits from this. It adjusts every number that matches a particular character style.
Useful when static references are used and client adds a new one in!
If anyone wants to improve it by, say, specifying at which number the adding begins, that's great.
Successfully used on one document so far.
-- Renumber (+1) based on char style - findChange a story at a time
-- Built with ChatGPT 5 March 2025
tell application "Adobe InDesign 2025"
-- Clear previous find preferences
set find grep preferences to nothing
-- Set GREP find preferences
set properties of find grep preferences to {applied character style:"_LOCAL-ITALIC REF# CAPTURED", find what:"\\d+"}
-- Get all stories in the active document
tell active document
set allStories to stories
-- Process each story separately
repeat with s in allStories
set foundItems to find grep of s
-- Process numbers in reverse order to prevent indexing issues
repeat with i from (count of foundItems) to 1 by -1
set t to item i of foundItems
try
-- Extract numeric text safely
set rawText to text of t as string
-- Ensure the text is a valid number
if rawText is not "" and rawText is not " " then
set newValue to (rawText as integer) + 1
set text of t to newValue as string
else
error "Unexpected non-numeric text: '" & rawText & "'"
end if
on error errorMessage
-- Get page number safely
set pageNumber to "Unknown (not in a frame)"
try
if (parent text frames of t is not {}) then
set pageNumber to name of parent page of item 1 of (parent text frames of t)
end if
end try
-- Get paragraph text safely
set paragraphText to "Unable to retrieve paragraph"
try
set paragraphText to contents of (paragraph of t)
end try
-- Display error message and stop script
set fullErrorMessage to "Error processing text: '" & rawText & "'" & return & ¬
"Page: " & pageNumber & return & ¬
"Paragraph: " & paragraphText & return & ¬
"AppleScript Error: " & errorMessage
display dialog fullErrorMessage buttons {"OK"} default button "OK"
-- Stop execution immediately after first error
return
end try
end repeat
end repeat
end tell
-- Clear GREP preferences after running
-- set find grep preferences to nothing
end tell