3 Replies Latest reply on Oct 25, 2016 7:44 AM by Silly-V

    applescript do javascript not working

    Silly-V Adobe Community Professional

      Hello, friends.


      Some applescript trouble.

      First, given the assignment, this could be completely done in JS - but that's not the question. I'm interested in how to make AS work the way I expect it to.

      I would like to know why this is happening here:


      this works:

      tell application "Photoshop"

           do javascript ...

      end tell


      but this does not:

      set myPs to "Photoshop"

      tell application myPs

           do javascript ...

      end tell


      I completely fail to see why it says "Expected end of line, etc. but found identifier." when it goes to "do javascript"

        • 1. Re: applescript do javascript not working
          Silly-V Adobe Community Professional

          MacScripter / Tell By Variable (herein of the Double-Tell)

          Here's a clue for myself from that page:
          "Telling the application—using the actual name of the application as a string literal as it appears on the compiling machine—satisfies the compiler, letting it know where the target application's dictionary is located."


          Maybe the answer would be to create an applescript string and run it from my applescript - but I'm not sure how to do his, and it sounds terrible..


          Aha! This place actually helped me understand, I think. If I on my machine when working on this script am able to use terms from application and have that application's name in a string explicitly - when this script it compiled into a run-only application for the customer, it'll have saved the application's dictionary and applied it to the tell block which uses the variable. So this could mean that I can 'cement in' the 'terms' from my application whose name I know for sure, and make the user's computer use them for other applications whose names I may not know.

          This is probably the answer - can anyone confirm?

          The goal is to have this applescript work on user's Photoshop CC versions going forward, without being sure if they have a specific version installed.



          global myPsName, myPsApp

          tell application "System Events"

            local appFiles, innerAppFiles, theFile

            set appFiles to every folder in folder "Applications" whose name contains "Photoshop CC"

            set innerAppFiles to every file in first item of appFiles whose name contains ".app"

            set theFile to (first item of innerAppFiles)

            set myPsName to name of theFile

          end tell


          using terms from application "Adobe Photoshop CC 2015.5"

            tell application myPsName

            --display alert ("HEY!")

            do javascript "alert(app.name);"

            end tell

          end using terms from


          ^ when this is compiled, it theoretically should be able to run the do javascript in Photoshop CC 201X because the app's dictionary has been packaged into this tell block when the script is exported as run-only app

          • 2. Re: applescript do javascript not working
            maxwyss Level 4

            This can be simplified by working with the application ID (which does not change as often and erratic as the application name), as in


              set myps to "com.adobe.Photoshop"

              set applName to (get name of application id myps)


            And then use the using terms from application command.

            1 person found this helpful
            • 3. Re: applescript do javascript not working
              Silly-V Adobe Community Professional

              Excellent, combined with what I have learned about compilation vs runtime and "using terms from", I believe that's all there is to this question.