20 Replies Latest reply on Jan 25, 2011 8:21 AM by Loic.Aigon

    app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");

    neweller Level 1

      Before the Extension Builder I was able to call AppleScript in the doScript() and run an AppleScript threw SwitchBoard. Has AppleScript been removed from the new SDK? It still shows up in the Docs for ScriptLanguage.

        • 1. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
          Bob Stucky Adobe Employee

          Hi neweller,

           

          I need more context to be able to answer your question.

           

          You're sending messages via switchboard - from what app to what app?

           

          The script you're sending via switchboard - what does it look like?

           

          Thanks

           

          Bob

          • 2. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
            neweller Level 1

            This is a package inside of a Extension Builder project for InDesign. It's just a button with that runs the run() function in this package. The problem is I can't get the project to compile because I get this error on doScript().

             

            Implicit coercion of a value of type String to an unrelated type com.adobe.indesign:ScriptLanguage.

             

            The HelloWorld.scpt is inside the project as a local resource. Do I need to load this an constant object and then load the path as a string?

             

            package mkt

            {

            import com.adobe.csawlib.indesign.InDesign;

            import com.adobe.indesign.*;

             

            public class MarketingAutomationInDesign

            {

            public static function run():void

            {

            var app:Application = InDesign.app;

             

            var document:Document = app.documents.add();

             

            var pages:Pages = document.pages;

            var firstPage:Page = pages.item(0);

             

            var layers:Layers = document.layers;

            var firstLayer:Layer = layers.item(0);

             

            var textFrames:TextFrames = firstPage.textFrames;

            var myTextFrame:TextFrame = textFrames.add(firstLayer);

             

            myTextFrame.label = "Dude Hope this works.";

             

            myTextFrame.geometricBounds = new Array("6p","6p","36p","36p");

            myTextFrame.contents = "Hello World from a Creative Suite Extension and again";

             

            var myItem:* = document.pageItems.itemByName("Dude Hope this works.");

             

            app.doScript("HelloWorld.scpt","applescriptLanguage");

             

             

            }

            }

            }

            • 3. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
              Harbs. Level 6

              doScript() should work fine.

               

              Like Bob, I have no idea where Switchboard comes into this picture.

               

              Harbs

              • 4. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                Bob Stucky Adobe Employee

                app.doScript( "HelloWorld.scpt", ScriptLanguage.APPLESCRIPT_LANGUAGE );

                 

                Should do the trick for you

                 

                Bob

                • 5. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                  neweller Level 1

                  Oh yes I did forgot that but when I try ScriptLanguage.APPLESCRIPT_LANGUAGE I get this.

                   

                  Error: A unknown token can’t go after this identifier.

                  at flash.external::HostObject/__call()

                  at com.adobe.csawlib::CSHostObject/hostCall()

                  at com.adobe.indesign::Application/doScript()

                  at mkt::MarketingAutomationInDesign$/run()[/Users/mattnewell/Documents/Adobe Flash Builder 4/MarketingAutomation/src/mkt/MarketingAutomationInDesign.as:30]

                  at main/___main_Button1_click()[/Users/mattnewell/Documents/Adobe Flash Builder 4/MarketingAutomation/src/main.mxml:38]

                  • 6. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                    Harbs. Level 6

                    Well, there you have it. You used a string instead of ScriptLanguage.APPLESCRIPT...

                     

                    Harbs

                    http://www.in-tools.com

                    Innovations in Automation

                    • 7. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                      Harbs. Level 6

                      There's probably an unknown token in your code...

                       

                      Harbs

                      • 8. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                        neweller Level 1

                        I'm gonna say No... This is the script.

                         

                        tell application "Adobe InDesign CS5"

                             display dialog "Hello World"

                        end tell

                        • 9. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                          Olav Martin Kvern Level 3

                          Hi neweller,

                           

                          A couple of further thoughts:

                           

                          Shouldn't the file be provided as a File object, rather than a string?

                           

                          Since the CS Extension can run on both the Mac OS and Windows, it might be a good idea to include a VBScript version. Trying to run an AppleScript in the Windows version of InDesign will return an error. (You may not need to worry about this--I'm just mentioning it for the sake of completeness.)

                           

                          I'll give this a try once I can get to a Mac OS machine that has both CS5 and Flash Builder on it.

                           

                          Thanks,

                           

                          Ole

                          • 10. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                            neweller Level 1

                            Come on Olav you know I'm a Mac guy

                             

                            I did try loading the script as a file instead of just a string.

                             

                            var script:File = new File();

                            script.resolvePath("HelloWorld.scpt");

                             

                            app.doScript(script,ScriptLanguage.applescriptLanguage);

                             

                             

                            But then I get some crazyness

                             

                            Error: Error #2037: Functions called in incorrect sequence, or earlier call was unsuccessful.

                            at Error$/throwError()

                            at flash.filesystem::File/resolveComponents()

                            at flash.filesystem::File/resolvePath()

                            at mkt::MarketingAutomationInDesign$/run()[/Users/mattnewell/Documents/Adobe Flash Builder 4/MarketingAutomation/src/mkt/MarketingAutomationInDesign.as:33]

                            at main/___main_Button1_click()[/Users/mattnewell/Documents/Adobe Flash Builder 4/MarketingAutomation/src/main.mxml:38]

                            • 11. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                              Harbs. Level 6

                              A string definitely works.

                               

                              How are you passing the string in?

                               

                              Harbs

                              • 12. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                Olav Martin Kvern Level 3

                                Hi neweller, Harbs,

                                 

                                I've finally gotten a chance to look at this. The following works fine for me:

                                 

                                var app:Application = InDesign.app;

                                //You'll have to fill in your own file path ("hazuki" is my root volume).

                                var applescript:File = new File("/hazuki/message.scpt");

                                app.doScript(applescript, ScriptLanguage.APPLESCRIPT_LANGUAGE);

                                 

                                Where message.scpt contains:

                                 

                                tell application "Adobe InDesign CS5"

                                display dialog "Hello from DoScript!"

                                end tell

                                 

                                I get the error you reported only when the file doesn't exist, or when the file is an uncompiled script (actually, an uncompiled script should work, but doesn't).

                                 

                                Running the script as a string, as in:

                                 

                                var applescript:String = "tell application \"Adobe InDesign CS5\"\rdisplay dialog \"Hello from DoScript!\"\rend tell\r";

                                app.doScript(applescript, ScriptLanguage.APPLESCRIPT_LANGUAGE);

                                 

                                ...always works.

                                 

                                I'd look at the way you've specified the file path. It has to be a fully-qualified path, including the volume name.

                                 

                                Thanks,

                                 

                                Ole

                                • 13. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                  Harbs. Level 6

                                  And I just took a better look at neweller's code as well...

                                   

                                  Passing in an ActionScript File object will definitely NOT work! The only File object which works is the ExtendScript kind. From ActionScript, you need to pass in the file path like so:

                                   

                                  app.doScript(script.nativePath,ScriptLanguage.APPLESCRIPT_LANGUAGE);
                                  
                                  

                                   

                                  Harbs

                                  • 14. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                    Harbs. Level 6

                                    Hmm. You say an ActionScript File object will work? Interesting. That must have been some fancy footwork!

                                     

                                    Passing in the file path DOES work with non-compiled scripts.

                                     

                                    Harbs

                                    • 15. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                      Olav Martin Kvern Level 3

                                      Hi Harbs,

                                       

                                      The file reference worked fine from ActionScript, no footwork needed.

                                       

                                      I'd also like to note that nativePath won't give you a colon-delimited path on the Mac OS. There are some cases (the poster image for a sound or movie, for example) where you need that sort of a path, and you'll have to convert them using RegExp. I'm going to start filing bugs for every instance in the DOM where file properties require a platform-specific string and won't accept a file reference. This is bad enough in ExtendScript, but it's even worse on the ActionScript side.

                                       

                                      Thanks,

                                       

                                      Ole

                                      • 16. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                        Harbs. Level 6

                                        Olav Martin Kvern wrote:

                                         

                                        Hi Harbs,

                                         

                                        The file reference worked fine from ActionScript, no footwork needed.

                                         

                                         

                                        Yes. I realize that. I meant fancy footwork implementing it!

                                         

                                        Hmm. I'm looking at some of my code where I used doScript(), and I think I used the file url rather than the nativePath (I've since changed my code to something which is of no use to this conversation). It looks like I used this regex to normalize it:

                                         

                                        script = script.replace(/^file:\/+/,"/");
                                        

                                         

                                        Harbs

                                        • 17. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                          Olav Martin Kvern Level 3

                                          Hi Harbs,

                                          For the rare cases where I need a Mac OS platform file path (e.g., sound poster images), I've been using:


                                          var fileString:String = file.nativePath; 
                                          //Only for the Mac OS. 
                                          fileString = fileString.replace(/\//g, ":"); // replace all “/” with “:” 
                                          fileString = fileString.replace(/^:/i, "");  // strip off first “:” 
                                          mySound.posterFile = fileString; 


                                          ...seems to work.

                                          Thanks,

                                          Ole

                                          • 18. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                            Loic.Aigon Adobe Community Professional

                                            Hi everyone,

                                             

                                            I tried to apply the doScript method and can't get it working. I put the test.jsx script in the project and in the panels folder but nothing seems to work.

                                             

                                            MXML

                                            <?xml version="1.0" encoding="utf-8"?>
                                            <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
                                                 <mx:Script>
                                                      <![CDATA[
                                                           import com.adobe.csawlib.indesign.InDesign;
                                                           import com.adobe.indesign.*;
                                                           
                                                           private function test():void{
                                                                var app:Application = InDesign.app;
                                                                app.doScript("test.jsx");
                                                           }
                                                      ]]>
                                                 </mx:Script>
                                                 <mx:Button x="18" y="36" label="Button" click="test()"/>
                                            </mx:WindowedApplication>
                                            

                                             

                                            test.jsx :

                                            alert("This is a test");
                                            

                                             


                                            The second point is that the external script is a scriptUI window with actions. It was intended to run like this at first but now, I intend to use Flex http abilities and so I need to communicate between the scriptUI window and the extension. The idea was to launch the scriptUi dialog from the extension to preserve the development done so far in extendscript.

                                             

                                            Could you please advice me about what is wrong ? I tried to find informations. I found HostObject that I use a lot. But as this is a scriptUI dialog with a targetengine, I don't know if I can include it. Oh my gosh, I think I need to rewrite it all in as3.

                                             

                                            Thanks anyway for your help.

                                             

                                            Loic

                                            • 19. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                              Harbs. Level 6

                                              All ExtendScript runs in the StageManager engine.

                                               

                                              You can target that engine, but I'm not sure it's 100% reliable.

                                               

                                              A better way would be to serialize the script and pass the string into the doScript (you can read the script file if you want) or load the function using the jsxInterface method and pass the function name into the doScript...

                                               

                                              Harbs

                                              • 20. Re: app.doScript("HelloWorld.scpt","APPLESCRIPT_LANGUAGE");
                                                Loic.Aigon Adobe Community Professional

                                                Thanks a lot Harbs (as usual )

                                                 

                                                I will try that asap.

                                                 

                                                Thx a lot,

                                                 

                                                Loic