Indesign change layer names

I have a range of 15-20 layers that I have to update in InDesign 5.5 many many times. The layer names look something like this:

AAA_Blue
AAA_Green
AAA_RED

And on and on. So what I am doing manually is changing the names to something like:

Birds_Blue
Birds_Green
Birds_Red

A script to help me change everything before “_” layer names in an open document would save me a ton of time.

On launch of the script ask me what I want there, I type it in and then click a button to set it in motion. As it is now I have to change one at a time for all 15-20 layers. And then repeat that process many times.

Thanks!

Hi there,

Welcome to MacScripter! :slight_smile:

Give this is try:


set newFirstBit to text returned of (display dialog "Enter new prefix" default answer "Please enter the new prefix...")

set theDelimiter to "_"

tell application "Adobe InDesign CC 2015"
	
	set theDocLayers to layers of front document
	
	repeat with i from 1 to (count of theDocLayers)
		
		set oldLayerName to name of item i of theDocLayers
		
		set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theDelimiter}
		set newLayerName to (newFirstBit & theDelimiter & text item 2 of oldLayerName)
		set AppleScript's text item delimiters to atid
		
		set name of item i of theDocLayers to newLayerName
		
	end repeat
	
end tell

Or, a bit shorter…


set newFirstBit to text returned of (display dialog "Enter new prefix" default answer "Please enter the new prefix...")

set theDelimiter to "_"

tell application "Adobe InDesign CC 2015"
	
	set {atid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, theDelimiter}
	
	repeat with thisLayer in (layers of front document)
		set theLayerName to name of thisLayer
		set name of thisLayer to (newFirstBit & theDelimiter & (text item 2 of theLayerName))
	end repeat
	
	set AppleScript's text item delimiters to atid
	
end tell

You’ll need to re-compile it for your version of InDesign.

HTH