Hi @Little_Matty, I have written a script that gives a great ability for renaming things, especially if you have a good text editor. I'm not sure if this is exactly what you want, but I couldn't resist sharing it here because I use this A LOT and find it very useful.
1. Run script (see below). You will see a large edit window with each item on a line of text.
2. Make changes to the text, any way you like, but keep the same number of lines (the line order is consequential).
Personally, I copy/paste into the free VSCode because it has *excellent* text editing features including multi-line editing and regular expression find/change. When you're finished editing, copy/paste the text back into the script window.
3. Press Apply button.
So, if you want to name Page Items, here is the script:
/**
* Edit Page Item Names As Text.js
* Can easily be re-purposed to change other properties as text.
* Change `settings.description`, `settings.things` and `settings.prop`.
* @author m1b
* @version 2024-01-14
* @discussion https://community.adobe.com/t5/indesign-discussions/looking-for-a-way-to-rename-indesign-layers-in-bulk/m-p/14353655
*/
(function () {
var settings = {
description: 'Rename Page Items',
things: app.activeDocument.pageItems,
prop: 'name',
before: [],
after: [],
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, settings.description);
/**
* Sets properties according to `settings` global object.
* @author m1b
* @version 2024-01-14
*/
function main() {
if (!settings.things)
return alert('Sorry there are no things for "' + settings.description + '".');
if ('function' === typeof settings.things.everyItem)
settings.before = settings.things.everyItem()[settings.prop];
if ('Array' === settings.things.constructor.name)
for (var i = 0; i < settings.things.length; i++)
settings.before[i] = settings.things[i][settings.prop];
// show UI
while (settings.before.length !== settings.after.length)
if (ui(settings) == 2)
return;
// set the properties
for (var i = settings.before.length - 1; i >= 0; i--)
if (settings.things[i][settings.prop] != settings.after[i])
settings.things[i][settings.prop] = settings.areNumbers
? Number(settings.after[i])
: settings.after[i];
};
})();
/**
* UI with large text edit field.
* Will update `settings.after` with
* final edited text, which must
* contain the same number of lines
* as `settings.before`.
* @author m1b
* @version 2024-01-14
* @param {Object} settings
* @param {Array<String>} settings.before - the before array of strings.
* @param {Array<String>} [settings.description] - a short description of what's going to happen (default: none).
* @returns {Number} - ScriptUI result code (1 = good, 2 = user cancelled).
*/
function ui(settings) {
var count = settings.before.length,
text = settings.before.join('\n');
var w = new Window("dialog", 'Editor by m1b'),
title = undefined == settings.description ? '' : settings.description + ' - ',
intro = w.add('statictext', undefined, title + 'Important: must have ' + count + ' lines.', { alignment: 'left' }),
textArea = w.add('edittext', undefined, text, { multiline: true, scrolling: true }),
row = w.add("Group {orientation:'row', alignment:['right','top'] }"),
cancelButton = row.add('button', undefined, 'Cancel', { name: 'cancel' }),
okButton = row.add('button', undefined, 'Apply', { name: 'ok' });
textArea.preferredSize.height = w.maximumSize.height - 400;
textArea.preferredSize.width = 600;
textArea.minimumSize.height = 250;
textArea.minimumSize.width = 200;
okButton.onClick = function () {
settings.after = textArea.text.split('\n');
if (count !== settings.after.length)
return alert('There must be '
+ count + ' lines of text, but there are '
+ settings.after.length + ' lines. Please fix and try again.');
w.close(1);
};
w.center();
return w.show();
};
Important note: many page items won't have a name to start with, so they will appear on a blank line and you must keep the same number of lines when Applying.
This is a very flexible script, so if you actually do want to rename Layers, just make settings look like this:
var settings = {
description: 'Rename Layers',
things: app.activeDocument.layers,
prop: 'name',
before: [],
after: [],
};
If you want to rename, say, Paragraph Styles, make settings look like this:
var settings = {
description: 'Rename Paragraph Styles',
things: app.activeDocument.allParagraphStyles,
prop: 'name',
before: [],
after: [],
};
Just for crazy demo, select a small amount of text or text frame and try this:
var settings = {
description: 'Set Character Sizes',
things: app.activeDocument.selection
&& app.activeDocument.selection[0]
&& app.activeDocument.selection[0].characters,
prop: 'pointSize',
areNumbers: true,
before: [],
after: [],
};
Anyway, if you find this script useful, please let me know. It's pretty bare bones, so feel free to elaborate on it, too.
- Mark