Copy link to clipboard
Copied
Ich erstelle täglich dutzende Inserate. Auf diesen Inseraten muss die Inserate-Nummer abgedruckt sein.
Der Name der Indesign-Datei lautet nicht wie die Inserate-Nummer. Das zu ändern ist leider keine Option.
Der Speicherordner der Indesign-Datei lautet aber wie die Inserate-Nummer.
Nun war meine Idee, eine Textbox zu erstellen, in der die Textvariable «Übergeordneter Ordner» steht.
Das ist aber leider nicht möglich, da es eine solche Variabel nicht gibt.
Hat jemand eine Idee? Ich habe ebenfalls schon versucht, ein Script zu erstellen. Dieses müsste aber manuell ausgelöst werden, was ebenfalls keine Option ist.
Hi @melanie_1280 oops! I forgot to attach demo.indd. I have posted it now on my original post.
Actually I never expected you literally open/close/re-open your real documents. I (wrongly) thought that you had hundreds of ad documents already existing and you wanted to get the parent folder name insert into them so all you needed to do was open them (once!).
But it sounds like you are creating new ad documents so a better way would be to use the "afterSave" and "afterSaveAs" events. See modifi
...Copy link to clipboard
Copied
If you have a script that inserts the advertisement number in a document, you can use a batch processor to run that script against folderfuls of documents. Two such scripts are
https://kasyan.ho.ua/indesign/batch_process_scripts/batch_process_scripts.html
https://creativepro.com/files/kahrel/indesign/batch_convert.html
Copy link to clipboard
Copied
Danke für den Input. Leider ist mein technisches Verständnis und Englisch nicht gut genug um das auszuführen.
Copy link to clipboard
Copied
@melanie_1280 another interesting approach could be to run an "afterOpen" event listener that performs the substitution automatically when a document is opened (if the document doesn't contain the target paragraph style, the script does nothing).
For a demonstration, before running the script open the attached "demo.indd" and save it into a folder called "AD1234567" (just an example fake ad number). At first you will see this:
This document has some text set in a particular paragraph style that the script is looking for.
Now run the script. A message appears: "Listener is running." Then close demo.indd and open it again.
You will see this:
where the text in magenta has been replaced with the parent folder's name. You can have any number of texts to replace.
I hope that is useful. The script listing is below.
- Mark
/**
* @file Populate With Parent Folder Name.js
*
* Will start an "afterOpen" event listener which will
* replace any text with the target paragraph style applied
* with the name of the document's parent folder.
*
* Once the script has been run, opening any document that has
* the target paragraph style will have the text(s) replaced.
* Note: the function will only happen when a document is opened.
*
* @author m1b
* @version 2025-12-13
* @discussion https://community.adobe.com/t5/indesign-discussions/textvariable-zu-speicherort/m-p/15629977/thread-id/644543
* @acknowledgement I am using Marc Autret's pattern for adding event listeners here - that cleverness is all his!
*/
(function (ev) {
/** the name of the paragraph style to target */
const PARAGRAPH_STYLE_NAME = 'Parent Folder Name';
/** Populates the found text with tje document's parent folder's name. */
function populate(text) {
text.contents = decodeURI(doc.filePath.name);
};
var listener;
if (!(ev || 0).isValid) {
// install the event listener (if not yet installed!)
const UID = 'populate_with_parent_folder_name';
// this script file
var file = File($.fileName);
if (
file.exists
&& !(app.eventListeners.itemByName(UID)).isValid
) {
// note: using this script file as the 2nd argument
listener = app.eventListeners.add('afterOpen', file);
listener.name = UID;
}
alert('Listener is running.');
return;
}
if ('afterOpen' != ev.eventType)
// not the right event
return;
var doc = ev.target || 0;
if (!(doc instanceof Document))
// not the right target
return;
var targetParagraphStyle = getThing(doc.allParagraphStyles, 'name', PARAGRAPH_STYLE_NAME);
if (!targetParagraphStyle)
return;
// use doScript so that the undo stack is nice and clean
app.doScript(populateAllTextInParagraphStyle, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Auto Populate');
function populateAllTextInParagraphStyle() {
app.findGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.appliedParagraphStyle = targetParagraphStyle;
var texts = doc.findGrep();
for (var i = 0; i < texts.length; i++)
populate(texts[i]);
};
/**
* Returns a thing with matching property.
* If `key` is undefined, evaluate the object itself.
* @author m1b
* @version 2024-04-21
* @param {Array|Collection} things - the things to look through.
* @param {String} [key] - the property name (default: undefined).
* @param {*} value - the value to match.
* @returns {*?} - the thing, if found.
*/
function getThing(things, key, value) {
for (var i = 0; i < things.length; i++)
if ((undefined == key ? things[i] : things[i][key]) == value)
return things[i];
};
})($.global.evt);
Copy link to clipboard
Copied
Das wäre grundsätzlich ein guter Ansatz. Leider habe ich keine Datei "demo.indd" gefunden.
Folgendes Problem besteht noch: Ich möchte die Indesign-Datei nicht schliessen und wieder öffnen. Wenn ich das bei jedem Inserat machen muss, generiert das zu viel zusätzlichen Aufwand.
Copy link to clipboard
Copied
Hi @melanie_1280 oops! I forgot to attach demo.indd. I have posted it now on my original post.
Actually I never expected you literally open/close/re-open your real documents. I (wrongly) thought that you had hundreds of ad documents already existing and you wanted to get the parent folder name insert into them so all you needed to do was open them (once!).
But it sounds like you are creating new ad documents so a better way would be to use the "afterSave" and "afterSaveAs" events. See modified script below: now it will make the substitution every time you save or saveAs. This time I remembered to attach my demo.indd for you to try it out! Try saving my demo document into different folders—it should update the magenta text accordingly.
- Mark
/**
* @file Populate With Parent Folder Name.js
*
* Will start an "afterSave" event listener which will
* replace any text with the target paragraph style applied
* with the name of the document's parent folder.
*
* Once the script has been run, opening any document that has
* the target paragraph style will have the text(s) replaced.
* Note: the function will only happen when a document is opened.
*
* @author m1b
* @version 2025-12-13
* @discussion https://community.adobe.com/t5/indesign-discussions/textvariable-zu-speicherort/m-p/15629977/thread-id/644543
* @acknowledgement I am using Marc Autret's clever pattern for adding event listeners here.
*/
(function (ev) {
/** the name of the paragraph style to target */
const PARAGRAPH_STYLE_NAME = 'Parent Folder Name';
/** Populates the found text with tje document's parent folder's name. */
function populate(text) {
text.contents = decodeURI(doc.filePath.name);
};
var listener1, listener2;
if (!(ev || 0).isValid) {
// install the event listener (if not yet installed!)
const UID = 'populate_with_parent_folder_name';
// this script file
var file = File($.fileName);
if (app.eventListeners.itemByName(UID).isValid)
app.eventListeners.itemByName(UID).remove();
if (
file.exists
&& !(app.eventListeners.itemByName(UID)).isValid
) {
// note: this script file is the 2nd argument
listener1 = app.eventListeners.add('afterSave', file);
listener2 = app.eventListeners.add('afterSaveAs', file);
listener2.name = UID;
}
return alert('Listener is running.');
}
if (
'afterSave' !== ev.eventType
&& 'afterSaveAs' !== ev.eventType
)
// not the right event
return;
var doc = ev.target || 0;
if (!(doc instanceof Document))
// not the right target
return;
var targetParagraphStyle = getThing(doc.allParagraphStyles, 'name', PARAGRAPH_STYLE_NAME);
if (!targetParagraphStyle)
return;
// use doScript so that the undo stack is nice and clean
app.doScript(populateAllTextInParagraphStyle, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Auto Populate');
function populateAllTextInParagraphStyle() {
app.findGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.appliedParagraphStyle = targetParagraphStyle;
var texts = doc.findGrep();
for (var i = 0; i < texts.length; i++)
populate(texts[i]);
};
/**
* Returns a thing with matching property.
* If `key` is undefined, evaluate the object itself.
* @author m1b
* @version 2024-04-21
* @param {Array|Collection} things - the things to look through.
* @param {String} [key] - the property name (default: undefined).
* @param {*} value - the value to match.
* @returns {*?} - the thing, if found.
*/
function getThing(things, key, value) {
for (var i = 0; i < things.length; i++)
if ((undefined == key ? things[i] : things[i][key]) == value)
return things[i];
};
})($.global.evt);
Copy link to clipboard
Copied
Huuuuuuui! Das geht!!! 🙂
Aber: Das Script muss aktiv ausgelöst werden. Gibt es eine Lösung, dass das automatisch gemacht wird sobald die Datei geöffnet wird?
Schon mal vielen, vielen Dank!
Copy link to clipboard
Copied
Hi @melanie_1280 after you run the script it will work on every document you Save (or Save As) until you quit Indesign. So you only have to run the script once when you are starting work.
To remove even that one manual operation: place the script into the Startup Scripts folder. You can find this folder by opening InDesign, choosing Window → Utilities → Scripts, then right-clicking (or Control-clicking) Startup Scripts and selecting Reveal in Finder (macOS) or Reveal in Explorer (Windows). Any script placed in this folder will execute automatically every time InDesign launches, without needing to be run manually.
Copy link to clipboard
Copied
Mark, du bist mein Held!!! Ich habe es nun mehrfach getestet und es funktioniert exakt so, wie es sollte! Ich bin beeindruckt!!! Danke vielmals!
Copy link to clipboard
Copied
Excellent! Glad it helped.
Copy link to clipboard
Copied
Weshalb nimmst du nicht eine Standardtextvariable?
Textvariabe, Typ Name, Pfad und Erweiterung einschließen
Copy link to clipboard
Copied
Weil mit einer Textvariable nur der komplette Speicherpfad eingeschlossen werden kann. Ich benötige aber nur einen Teil des Pfades. Und leider lässt sich nichts ausschliessen.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more