11 Replies Latest reply on Jan 11, 2012 12:04 AM by Harbs.

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

    Roy Marshall Level 1

      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

        • 1. Re: Accent Problem Running a pre-built AS in JS using doScript
          John Hawkinson Level 5

          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.

          1 person found this helpful
          • 2. Re: Accent Problem Running a pre-built AS in JS using doScript
            Roy Marshall Level 1

            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

            • 3. Re: Accent Problem Running a pre-built AS in JS using doScript
              Roy Marshall Level 1

              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.

              • 4. Re: Accent Problem Running a pre-built AS in JS using doScript
                Muppet Mark Level 5

                Roy you have me confused by this process… Why do you want to construct a complied AppleScript file… to then read the contents as a string for ExtendScript…? Can't you… A. construct an AppleScript string on the fly and pass that or B. pass the file as object?

                • 5. Re: Accent Problem Running a pre-built AS in JS using doScript
                  John Hawkinson Level 5

                  Hi, Roy.

                   

                  Glad to see you getting straightend out. Perhaps it's a nit, but I think it's worth some time:

                  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++.

                  Nope, it's not a plugin!

                  Please don't call it one!

                  You will certainly confuse us here.

                   

                  But you will also confuse your users, when they find instructions for dealing with InDesign plugins, and they don't match up. Files in the Plugins folder, etc.

                   

                  Just call it a script. Thanks!

                  • 6. Re: Accent Problem Running a pre-built AS in JS using doScript
                    Roy Marshall Level 1

                    Hi Mark.

                     

                    I have tried running the AS by passing the file:

                     



                    app.doScript(appleScript,ScriptLanguage.APPLESCRIPT_LANGUAGE);

                     

                    "Incompatible or unsupported scripting language"

                    The file is valid because it is the same file I am opening and reading as as a string:

                     

                    var appleScript= File(applescriptFilePath);

                    appleScript.encoding="UTF-8";

                    appleScript.open("r");

                    var appleScriptString = appleScript.read();

                    Any suggestions as to where I am going wrong would be gratefully recieved!

                     

                    Roy

                    • 7. Re: Accent Problem Running a pre-built AS in JS using doScript
                      Muppet Mark Level 5

                      Roy, I will have to do some checking/testing myself… Like John I try to keep the scripting languages down to absolute minimum… What I didn't really understand was if you are constructing a 'script' as text on the fly then why AppleScript to then call from ESTK could you not have just constructed an ExtendScript? As InDesign is the only CS app that has this doScript() I have not used it a lot… I would first suspect the issue is from 'compiled syntax' have you tried passing the file as a saved script but NOT compiled syntax? Again without seeing an example of your code ESTK and AppleScript then its pure speculation…

                      • 8. Re: Accent Problem Running a pre-built AS in JS using doScript
                        John Hawkinson Level 5
                        app.doScript(appleScript,ScriptLanguage.APPLESCRIPT_LANGUAGE);

                        The file is valid because it is the same file I am opening and reading as as a string:

                         

                        var appleScriptString = appleScript.read();

                        Does it work if you pass it appleScriptString?

                        What about if you run "osascript FILENAME" in the Terminal?

                        • 9. Re: Accent Problem Running a pre-built AS in JS using doScript
                          Roy Marshall Level 1

                          Hi John/Mark.

                           

                          It seems I need to have .applescript as a suffix for anything to work. Testing with a simple InDesign Alert works fine.

                          When using my pre-compiled Applescript I get the error "Expected expression but found unknown token".

                           

                          When running through Terminal as Johns suggestion, it runs OK, (with or without the .applescript suffix).  I guess I need to find a way to pass a shell script, containing a reference to an applescript, from a Javascript.  When I put it this way I am questioning my sanity!

                           

                          I will still pursue this anyway just for a laugh.

                           

                          Thanks for your help.

                           

                          Roy

                          • 10. Re: Accent Problem Running a pre-built AS in JS using doScript
                            John Hawkinson Level 5

                            Roy, I'm confused how you're getting pre-compiled Applescript, but if that's what you've got, yeah, that's what you got and you can't run it with doScript. So you'll need to call "osascript" to do it, or you can probably do it from Applescript as well. the osascript route is faster for me, because I can write it right here:

                             

                            app.doScript('do shell script "osascript filename"', ScriptLanguage.APPLESCRIPT_LANGUAGE);

                             

                            Though the applescript way is probably better.

                            • 11. Re: Accent Problem Running a pre-built AS in JS using doScript
                              Harbs. Level 6

                              Umm...

                               

                              This:

                               

                              app.doScript(appleScript,ScriptLanguage.APPLESCRIPT_LANGUAGE);

                               

                              Does not match this:

                              var appleScriptString = appleScript.read();

                              You should be passing in the appleScriptString instead of the file. (although I would have thought the file would work)

                               

                              If it's compiled, I'm not sure UTF-8 is the way to go, but I could be wrong.