Copy link to clipboard
Copied
Hello everyone,
I'm reaching out to see if it's possible to create a script to automate a specific task. I work daily for a company whose name contains a thin space (for example: N (thin space) NAME = N NAME).
The issue is that I sometimes forget to add this space when formatting lengthy documents.
I’d like to know if it’s possible to create a script that automatically detects the company’s name (N NAME) and inserts the thin space between “N” and “NAME” whenever the name is written.
Thank you so much for your help, and have a great day!
<Title renamed by MOD>
Hi @Océane23259082birw, you could do this as a straight find grep, without a script:
If you need a script, this does pretty much the same thing—using find/change grep. It will target the selected text/textframe(s) or, if nothing selected, the whole document.
- Mark
function main() {
var doc = app.activeDocument,
targets = doc.selection;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.propertie
...
Instead of inserting a space use a character style with expanded tracking for the space before. This can be automatically applied via GREP style.
Copy link to clipboard
Copied
Depending the actual name of the company, you could “fake” a thin space using a GREP style.
Copy link to clipboard
Copied
You don't need a script or thin space.
Create a character style that only uses the ‘No Break’ attribute.
In the paragraph style used for your text, add a GREP style that applies the ‘No Break’ style to the words ‘N Name’.
You'll never forget these words again.
Copy link to clipboard
Copied
Hi @JR Boulay since the OP asks for a thin space, I assume that the GREP style needs more that a no break attribute, but also a 50 % horizontal scale.
Copy link to clipboard
Copied
Hi @Océane23259082birw, you could do this as a straight find grep, without a script:
If you need a script, this does pretty much the same thing—using find/change grep. It will target the selected text/textframe(s) or, if nothing selected, the whole document.
- Mark
function main() {
var doc = app.activeDocument,
targets = doc.selection;
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
app.findGrepPreferences.properties = {
findWhat: '(?<=\\bN)\\s(?=Name\\b)',
};
app.changeGrepPreferences.properties = {
changeTo: '~%',
noBreak: true,
};
if (0 === targets.length)
targets = [doc];
for (var i = targets.length - 1; i >= 0; i--)
if (undefined != targets[i].changeGrep)
targets[i].changeGrep();
};
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Apply N Name Spacing');
Edit 2024-10-08: added check to see if selected item was greppable.
Copy link to clipboard
Copied
Instead of inserting a space use a character style with expanded tracking for the space before. This can be automatically applied via GREP style.