Copy link to clipboard
Copied
Good day,
Is it possible to insert content of clipboard after a specific character with a script?
For example, I have a piece of specifically formatted text, which I need to insert after every "-"-sign in every text block of a document.
I imagine, first the cursor should be moved to the position after hyphen-sign and then the script should fire the command Paste.
Can somebody help me with code?
Copy link to clipboard
Copied
Can you elaborate on what you mean by 'specifically formatted' ?
Copy link to clipboard
Copied
For example, a chemical formula with digits in subscipt, C12H22O11, or a piece of text with some characters in bold some in italic.
Classical Find/replace/regex scripts just replace characters and do not count on the formatting.
It seems, the simplest option to keep formatting is to paste already formatted text from the clipboard.
Copy link to clipboard
Copied
I was going to suggest looking here:
Re: RegExp search and replace, keep original text formatting
However, you may actually be looking to replace a string with text that may have multiple style ranges within the same text-match?
Copy link to clipboard
Copied
Well, maybe you are right. If you want, I need to replace text "-" by "- C12H22O11", with all digits subsript.
In my opinion, the algorithm is pretty simple.
The script should move the cursor to the correct position within text string and execute something like app.executeMenuCommand('paste').
My problem is that I have no idea how to move the cursor to the right position and whether it is possible at all.
Copy link to clipboard
Copied
Can you post a screenshot of what this looks like? Pasting may be okay, and cursor stuff is handled by selecting the text range matching the '-' character, and pasting would not be necessary because at that point you just set the contents of the text range to your word, it should take on the styling originally applied to the '-'. So the thread I pointed out may work anyway.
But it may not work if your 'copied' item is something looking like this: C12H22O11
Copy link to clipboard
Copied
Bonjour,
Il faut utiliser : textRf.insertionPoints[index];
caractère par caractère...
Ici je remplace des par H2S04 formaté size font color
Copy link to clipboard
Copied
to Silly-V:
For example:
to renél80416020:
Many thanks for the suggestion.
What is under the textRf? Text reference?
Could you please show the final code to insert the content of the clipboard to the position after every hyphen-sign?
I am not so much experienced in js coding to regret.
Copy link to clipboard
Copied
Bonjour,
Je n'utilise pas (copy\paste) mais un text placé au premier plan reconnu par le symbole @.
ce text peut comporter plusieurs lignes pour des remplacements successifs.
Remplacer le chien par le loup
Comme :
@le chien:le loup
la vache:la chêvre
....
- J'ai simplement ajouté pour l'occasion 5 lignes à un script existant
que je fourni à des clients, ce qui explique [i+4], ces lignes
commencent par curentChar .
Ce script peut remplacer des groupes de mots par d'autres groupes en
conservant le style du texte d'origine pour tous les documents ouverts.
Je donne juste le principe :
index = textRf.contents.search(RegExp(rx,drap));
if (index != -1) {
fg = new RegExp(rx).exec(textRf.contents);
ip = textRf.insertionPoints[index];
for(i = 0; i < ch.length; i++) {
ip = textRf.insertionPoints[index];
ip.characters.add(ch.charAt(i));
curentChar = textRf.characters[index];
curentChar.textFont = text.characters[i+4].textFont;
curentChar.size = text.characters[i+4].size;
curentChar.fillColor = text.characters[i+4].fillColor;
curentChar.baselineShift = text.characters[i+4].baselineShift;
index++;
}
Copy link to clipboard
Copied
renél80416020, many thanks for the answer.
But for me your snippet of a little use because I cannot transform it into the final code.
Would you or somebody else be so kind to help with the transforming into the working script?
Copy link to clipboard
Copied
Sylvio,
Je veux bien t'aider mais il faut me faire parvenir un document .ai avant et après transformation,
avec les explications utiles par mail. (voir Photo)
Pour travailler en situation réelle.
A+
Find more inspiration, events, and resources on the new Adobe Community
Explore Now