0

I have a script that takes the contents of the clipboard and writes them to a file so that I can paste the content into InDesign. It was working earlier but now it is replacing all the quotes with these characters, "”". I'll paste the before and after:

Before:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?aid style="50" type="snippet" readerVersion="6.0" featureSet="257" product="8.0(370)" ?>
<?aid SnippetType="PageItem"?>
<Document LinkedSpreads="" DOMVersion="8.0" Self="d">
</Document>

After:

<?xml version=”1.0” encoding=”UTF-8” standalone=”yes”?>
<?aid style=”50” type=”snippet” readerVersion=”6.0” featureSet=”257” product=”8.0(370)” ?>
<?aid SnippetType=”PageItem”?>
<Document LinkedSpreads=”” DOMVersion=”8.0” Self=”d”>
</Document>

I normally can tell if my code changes things but I think I may have changed something in InDesign? I'm going back through my changes to see if it's something I did but in the mean time has anyone seen this?

If I paste the code into a .idms file and then place the document it continues to work. It's the script that is having issues.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • 1
    I too encountered this when using the character `“` in my CSVs, but it was displayed as ‚Äù in Microsoft Excel. Had to switch to the regular `"`. – Amit Beckenstein Dec 13 '22 at 13:30

1 Answers1

0

I'm not sure what it was but I did not set the file encoding to "UTF-8" and it appears to be working now. Here is a snippet of the code I'm using:

doc.textPreferences.typographersQuotes = false;
var tf = doc.textFrames.add();
var story = tf.parentStory;
//story.appliedLanguage = app.languagesWithVendors[0];
story.insertionPoints[0].select();
app.paste();
var str = story.contents;
if (str.indexOf("‚Äú")!=-1 || str.indexOf("Äù")!=-1) {
    alert("Weird quotes found. Try saving to an .idms file and then placing it.");
    //str = str.replace("”", '"');
    //alert(str.substr(0,200));
 }

tf.remove();
var f = File(Folder.temp + "/temp_snippet.idms");
//f.encoding = "UTF-8"; // commented out here
f.open('w');

But I have since uncommented that line again and it's still working. Gremlins.

Update: it stopped working. Then it started working again. Then stopped. All without modifying the import code. It continues to work if I save it to an IDMS text file first rather than copy it to the clipboard.

Here is the full script, http://pastebin.com/F5Re4C2R.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • That is a character encoding error, as you have spotted yourself. The reason it might still work could be because it originally assumed a new file should be in UTF-16 or Unicode. Now that it is once explicitly saved as UTF-8 the autodetect could do its job and find the correct encoding. – Einar Sundgren Apr 02 '15 at 18:03
  • I've added a link to the script I've used. – 1.21 gigawatts Apr 15 '15 at 19:19