10 Replies Latest reply on May 9, 2013 12:33 AM by SureshRaji

    Applescript to run javascript

    SureshRaji

      Hi all,

       

      I got error in this script. Could anyone help on this?

       

      tell application "Finder"

          activate

          set myApps to {"CS3", "CS4", "CS5"}

          set selectedApp to choose from list myApps with prompt "Choose Application:" with title "Launch Application"

          if the result is not false then

              set myApp to "Adobe InDesign " & selectedApp

              display dialog myApp

              set myFile to "Applications:" & myApp & ":Scripts:Scripts Panel:Sample.jsx"

             

              tell my application myApp

                  activate

                  run script file myFile   // error "Adobe InDesign CS4 got an error: A unknown token can’t go after this “)”." number -2740

              end tell

          end if

      end tell

       

      Regards

      Suresh

        • 1. Re: Applescript to run javascript
          Vamitul Level 4

          hey suresh..

          can't realy remember the last time i used applescript, but still here are my two cents:

          the javascript you are trying to run has a error somwhere in it. open it in estk and try a "Check Syntax" (form the edit menu)

          • 2. Re: Applescript to run javascript
            SureshRaji Level 2

            Hi Vamitul,

             

            Thanks for your quick response. I  checked the javascript in ESTK which shows no error.

            Even if I write a simple javascript (an alert message), applescript throw an error in the same line.

             

            Regards

            Suresh

            • 3. Re: Applescript to run javascript
              Vamitul Level 4

              ok...

              tell application "Finder"
                  activate
                  set myApps to {"CS3", "CS4", "CS5"}
                  set selectedApp to choose from list myApps with prompt "Choose Application:" with title "Launch Application"
                  if the result is not false then
                      set myApp to "Adobe InDesign " & selectedApp
                      display dialog myApp
                      set myFile to "Applications:" & myApp & ":Scripts:Scripts Panel:Sample.jsx"
                       set myScript to POSIX path of myFile 
                     
                      tell my application myApp
                          activate
                          run script file myScript 
                      end tell
                  end if
              end tell
              
              • 4. Re: Applescript to run javascript
                SureshRaji Level 2

                Hi Vamitul,

                 

                Thanks for showing a different way to specify the path. It  throw an error in same line like this.

                 

                run script file myScript // error "Adobe InDesign CS4 got an error: Can’t make some data into the expected type." number -1700 to item

                • 5. Re: Applescript to run javascript
                  Vamitul Level 4

                  aa.. it's do script, not run script. (just checking form the scripting guide) try:

                  do script alias myScript language javascript

                  1 person found this helpful
                  • 6. Re: Applescript to run javascript
                    SureshRaji Level 2

                    Hi Vamitul,

                     

                    It works fine when I edit the  script like this:

                     

                    tell application "Finder"
                        activate
                        set myApps to {"CS3", "CS4", "CS5"}
                        set selectedApp to choose from list myApps with prompt "Choose Application:" with title "Launch Application"
                        if the result is not false then
                            set myApp to "Adobe InDesign " & selectedApp
                            display dialog myApp
                            set myFile to "Applications:" & myApp & ":Scripts:Scripts Panel:Sample.jsx"
                            --set myScript to POSIX path of myFile
                    
                            tell application "Adobe InDesign CS4"
                                activate
                                do script alias myFile language javascript
                            end tell
                        end if
                    end tell
                    

                     

                    But how could I run to selected Application.

                     

                    Regards

                    Suresh

                    • 7. Re: Applescript to run javascript
                      Muppet Mark Level 5

                      tell application myApp

                           activate

                           do script alias myFile language javascript

                      end tell

                      • 8. Re: Applescript to run javascript
                        SureshRaji Level 2

                        Hi Mark

                         

                        Thanks for your reply. But it shows an error at this line

                         

                        do script alias myFile language javascript

                         

                        Reference.png

                        • 9. Re: Applescript to run javascript
                          -hans- Level 4

                          Hi,

                           

                          you're right. The script does not compile. I don't know the reason, perhaps Shane reads the thread and knows the answer. Macscripter.net may be a good point for posting this.

                           

                          A workaround: Create the whole ID-Tellblock as string and do a vanilla run script command.

                           

                          tell application "Finder"
                              activate
                              set myApps to {"CS3", "CS4", "CS5.5"}
                              set selectedApp to choose from list myApps with prompt "Choose Application:" with title "Launch Application"
                              if the result is not false then
                                  set myApp to "Adobe InDesign " & selectedApp
                                  set myFile to "Applications:" & myApp & ":Scripts:Scripts Panel:Sample.jsx"
                              end if
                          end tell
                          
                          set myString to "tell application " & "\"" & myApp & "\"" & return ¬
                              & "do script alias " & "\"" & myFile & "\"" & " language javascript" & return ¬
                              & "end tell"
                          
                          run script myString
                          

                           

                          It runs here.

                          • 10. Re: Applescript to run javascript
                            SureshRaji Level 2

                            Hi hans

                             

                            Thankyou. This works fine for me.

                             

                            Thanks for everyone those who given me your suggestion.

                             

                            Regards

                            Suresh