Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

[JS] Variable text constructor

Enthusiast ,
Dec 15, 2015 Dec 15, 2015

Hello,
I can not do it on replacing these two variables, the result is not good and there, I'm stuck.

Thanks for your help

Bonjour,

je ne parviens pas à faire le remplacement sur ces deux variables, le résulta n'est pas bon et là, je suis bloqué.

Merci pour votre aide

var paragraph0 ="Chépitre 01.indd";

var paragraph = app.activeDocument.name; //name file indesign is Chépitre 01.indd.

alert(paragraph0.replace (/é/g, 'e') +'—' + paragraph.replace (/é/g, 'e'));

result : "Chepitre 01.indd — Chépitre 01.indd" -> not good


TOPICS
Scripting
762
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Dec 15, 2015 Dec 15, 2015

I've tested the code you've posted and it works as you expect. Result is: Chepitre 01.indd—Chepitre 01.indd

Maybe you'll need to add more details so we can reproduce your problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 15, 2015 Dec 15, 2015

I agree with Luca Bisin. I saved a document as "Chépitre 01.indd" and ran your script. This was the result:

Capture.PNG

What version of InDesign do you have? This was CC 2015.2 (latest CC version).

Perhaps there might be another ASCII / UTF8 representation of the letter "é" in the filename, than the letter é that we are testing with.

Andreas

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 15, 2015 Dec 15, 2015

I second that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 15, 2015 Dec 15, 2015

I work on mac (10.7.5) with InDesign CS6 (8.1), I just tested it on another machine, I have no problem (!!! ?????).

Is it possible to reach saturation or other problem?
I return on another machine tomorrow.

thank you to all of you


Je travail sur mac (10.7.5) avec indesign CS6 (8.1), je viens de tester sur une autre machine, je n'ai plus le problème (!!!?????).

Est-il possible d'arriver à saturation ou autre problème ?

Je retour sur l'autre machine demain.

Merci à vous tous

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Dec 15, 2015 Dec 15, 2015

Where do your document come from. Was it created and saved at your office ?

It looks like it was created on some other machine using a different encoding. Guessing that Chépitre would stand orginally for Châpitre. So the possible â to é translation would betray a change of encoding leading to characters mismatch.

One thing to try would be to do a idml loop to see if once reconstructed you would still face the issue.

FWIW

loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2015 Dec 15, 2015

Hi Liphou,

I can see the same as you with InDesign CS6 v8.1.0 on Mac OSX 10.7.5.

I copied the contents of your first string to the "Save As" editing field of an unsaved InDesign document and saved the file with this name.

Then I ran the following code on the open document:

var string1 = "Chépitre.indd";

var string2 = app.documents[0].name;

$.writeln(string1.length); // 13

$.writeln(string2.length); // 14

I think, that's the proof that é in string2 is composed of two components: e + ´


So let's check this a bit in more depth:

var string1 = "Chépitre.indd";

var string2 = app.documents[0].name;

$.writeln("string1.length" +"\t"+ string1.length);

// string1.length    13

$.writeln("string2.length" +"\t"+ string2.length); //EDITED

// string2.length    14 //EDITED

$.writeln("string1:");

for(var n=2;n<4;n++){

    $.writeln(string1.slice(n,n+1) +"\t"+ string1.charCodeAt(n));

    };

/*

    string1:

    é    233

    p    112

*/

$.writeln("string2:");

for(var n=2;n<4;n++){

    $.writeln(string2.slice(n,n+1) +"\t"+string2.charCodeAt(n));

    };

/*

    string2:

    e    101

    ́    769

*/

That's it…

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2015 Dec 15, 2015

Btw. I'm on a German OSX with a German version of InDesign CS6.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2015 Dec 15, 2015

Tested a bit more. On my German Mac OSX 10.7.5.

var string = "Chépitre.indd";

1. If I copy/paste the string over to the ESTK and then on to the Save As dialog to save an InDesign document, I get this: e + ´

2. If I rename an InDesign document in the Finder to the contents of the string using the keyboard any typing an ´ followed by an e, I also get this as app.documents[0].name : e + ´

3. If I copy/paste the string from the ESTK directly to the file name in the Finder to rename the InDesign document, I get: é with app.documents[0].name

4. If I copy/paste the string to an TextEdit file set to "Pure Text" with Encoding UTF8 and then copy/paste to the InDesign file in the Finder, I will get : é with app.documents[0].name


Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 15, 2015 Dec 15, 2015

Laubender thank you for your answer,

I used your code and I had no difference
so I copied the contents of my first string and "save as" the documents, I crashed the other file, I raise the code and I have the problem again.

Ok, two things but why ???

The file is located on a "Google Drive" ... the problem may be due to the transfer.
I had a problem at work but at home ... to meditate

Thank you.


Merci Laubender pour ta réponse,

j'ai utilisé ton code et je n'avais plus de différence,

j'ai donc copié le contenu de ma première chaîne et « enregistrer sous » le documents, j'ai ecrasé l'autre fichier, je relance le code et j'ai de nouveau le problème.

Ok, deux éléments mais pourquoi ???

Le fichier se trouve sur un "google Drive" ... le problème est peut être du au transfert.

J'avais le problème au travail mais plus chez moi ... à méditer

merci

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 15, 2015 Dec 15, 2015

Hi Liphou,

in this regard see the following post by Martin Fischer at www.hilfdirselbst.ch in German.

He is using a table of replacements for Umlauts, because he had the same problems.

See his String.prototype.cleanUmlaut function.

Textdatei Importoption Zeichensatz Unicode - Adobe InDesign -  HilfDirSelbst.ch - Forum

In this post (back in 2008) he stated that he had no problems with combinations of áàéèóòúù, but years later he or someone else (including me) stumbled upon these and expanded his function. I recall a function that is placing images according to a list of file names that had the problems you encounter now.

See also from the same website from 2012:

Encodingdifferenzen zwischen Filesystem und javascript prompt
(differences of encoding between fle system and the javascript prompt)

Johannes Puff

http://www.hilfdirselbst.ch/foren/Encodingdifferenzen_zwischen_Filesystem_und_javascript_prompt_P494...

And also this one on hilfdirselbst from 2006:

http://www.hilfdirselbst.ch/foren/_P267653.html?search_string=Diaresis#267653

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Dec 16, 2015 Dec 16, 2015
LATEST

Good evening and thank you Laubender for all these documentations.

To summarize,
so I copied the contents of my first string and "save as" the documents, I crashed the other file, I raise the code and I have the problem again.

I close the document, I open it again and resumes code ... no problem ...

thank you to all of you

// ----------------------

Bonsoir et merci Laubender, pour toutes ces documentations.

Pour résumer,

j'ai donc copié le contenu de ma première chaîne et « enregistrer sous » le documents, j'ai ecrasé l'autre fichier, je relance le code et j'ai de nouveau le problème.

je ferme ce document, je l'ouvre à nouveau et relance le code ... plus de problème ...

Merci à vous tous 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines