Skip to main content
Roy Marshall
Known Participant
January 4, 2012
Question

Accent Problem Running a pre-built AS in JS using doScript

  • January 4, 2012
  • 1 reply
  • 1957 views

Hi.

I am working with some software that builds dynamic AS files that are used to build pages in InDesign. In order to keep this in a JS environment, I am writing my own plugin to read these files, and using doScriot to carry out the AS.

The AS files are fine, and build finished pages with no problems. However, with non standard characters such as accents, copyrights etc I am getting incorrect text on my page.

See below.

...

tell page 1 of doc1

set tx0 to make text frame with properties{geometric bounds:{"33.1mm", "10.0mm", "315.9mm", "32.85714285714286mm"}, contents:"P1L0H0S0R1C1

é = 00E9

É = 00C9

á = 00E1

í = 00ED

ó = 00F3

ú = 00FA

" as Unicode text}

...

but when I process this through JS, I get this:

...

tell page 1 of doc1

set tx0 to make text frame with properties{geometric bounds:{"33.1mm", "10.0mm", "315.9mm", "32.85714285714286mm"}, contents:"P1L0H0S0R1C1

é = 00E9

É = 00C9

√° = 00E1

í = 00ED

ó = 00F3

√∫ = 00FA

" as Unicode text}

...

Is there a certain filter I need to be parsing the text through to keep the characters?

Many Thanks in advance

Roy Marshall

This topic has been closed for replies.

1 reply

John Hawkinson
Inspiring
January 4, 2012

I am working with some software that builds dynamic AS files that are used to build pages in InDesign. In order to keep this in a JS environment, I am writing my own plugin to read these files, and using doScriot to carry out the AS.

Wait, what? You are writing a C++ plugin to read AppleScript files and somehow using Javascript (you don't say why or how) to execute the Applescript? Or is one of your ASes ActionScript?

This sounds kind of like you need your head examined...except for the rare gaps in featuresets between the different languages, it's usually a good idea to avoid multiple languages. And I'm not sure why you would want a C++ plugin. It doesn't sounds like it is necessary and they are extremely painful and costly to develop.

but when I process this through JS, I get this:

What does "process" mean? Show us the code!

Clearly you've got the wrong character set. Either you're not reading the file as UTF-8 or some other Unicode format, or your dynamic applescript isn't writing it that way. Check and see which it is by examination, and by looking at your file in an app that tells you. You almost certainly want to be using the unicode encoding rather than something else.

Roy Marshall
Known Participant
January 4, 2012

Hi John.

Thanks for the reply.

First, I am overstating the 'plugin' angle. It is just a couple of js files triggered from a session palette, triggered from a custom pull down menu. For the user who doesn't ask too many questions, it is a plugin. For you it is simply JS. I have not used C++.

The company I work for make an online product database which users compose mailer/catalogue pages with, and then when the page is submitted, a AS file is created. This file sits in a hidden folder on the connected server volume, and a companion java app is used to read the file, and build the page.

My boss, who made all the software, is happy with the current solution, but I have shown him the JS alternative to his Java app and he is keen to use it instead of his Java app. He wont be re-coding anything any time soon, but ultimately he will change the process to generate JS instead of AS.

So for now, I am stuck with accessing a fully compiled AS file, and running through a doScript option. This works perfectly apart from the characters I mentioned earlier.

I hope this had made things clearer.

but when I process this through JS, I get this:

When I read the file into a JS String to carry out some new line replacements that get lost in the transfer, the string contains the text I posted. This differs from the AS file being opened in Komodo/Text Wrangler or Script Editor.

I guessed it was a character set issue, but dont know how to address this. Can you help me here? Maybe if I get this sorted, I wont need to use my script to carry out the other changes as these could also be as I am using the wrong character set.

Anyway, sorry this is such a long reply, but needed to explain myself!

Cheers as always

Roy

Roy Marshall
Known Participant
January 4, 2012

OK, got this.


var appleScript= File(applescriptFilePath);

appleScript.encoding="UTF-8";

appleScript.open("r");

var appleScriptString = appleScript.read();

This seems to work ok. Will carry on testing.