1 Reply Latest reply on Apr 12, 2017 6:49 AM by Sturm359

    folder-dependent launching of jsx file from applescript

    Sturm359 Level 1

      I have updated our main .jsx script that runs in InDesign so that it takes different parameters and returns a different value. However, I have now run into the *strangest* situation. Normally, this script is called from an applescript which, at a very basic level, looks like this:



      set server_prefix to "/Volumes/ArtDept/ArtDept/Scripts/sky-artdept/Test/"

      set is_defined to true

      set jLogging to "true"

      set json to "{...some json data here...}"



      tell application id "com.adobe.InDesign"


        set myJavaScript to server_prefix & "OutputJ.jsx"

        set myResult to do script myJavaScript with arguments {json, jLogging} language javascript



          get myResult

        on error

          set is_defined to false

        end try


      end tell



      This works perfectly. It *has* worked this way for years. However, there is a new wrinkle. If I copy the OutputJ.jsx file to its parent folder and change the first line to read:


      set server_prefix to "/Volumes/ArtDept/ArtDept/Scripts/sky-artdept/"


      The script fails with the message that InDesign could not find the file or folder. This is quite literally the *only* change that I make to the applescript. Its sole purpose is to call the Extendscript javascript file from within InDesign, passing in a couple of variables. It also does this when I test it directly from within MacOS's Script Editor. I know that the applescript can find the folder just fine, as I do have a check in there for that. (I've omitted that check from the script above to keep it simple). Now, what's even *more* confusing is that, if I replace that OutputJ.jsx file in the parent folder (".../sky-artdept/") with a previous version of it, then InDesign finds the file just fine and runs it.


      Could there, perhaps, be some odd line breaks or other strange, unseen characters in the updated OutputJ.jsx file that might cause this problem? Or could it be a permissions issue on the file itself? Or some odd SMB/networking issue? It makes no sense to me that InDesign can find the file perfectly fine if it resides in the ".../sky-artdept/Test/" child folder, but not if it's in the parent ".../sky-artdept/" folder.

        • 1. Re: folder-dependent launching of jsx file from applescript
          Sturm359 Level 1

          When going through the folder & file structure of both the parent & child folders, I came upon the answer.


          It turns out that the new version of OutputJ.jsx imports a separate .js file (json2.js) to handle my new way of transferring data--via JSON strings. I had completely forgotten to copy over this file as well when I copied the OutputJ.jsx file to the parent folder. Thus, it was referencing a file that didn't exist. And since imports (with ExtendScript, at least) are preprocessor directives, they are evaluated before any other actual code is run. So when I was getting a "InDesign could not find the file or folder" message, I assumed it meant the OutputJ.jsx file, not the json2.js file it was attempting to import.


          So, the mystery has been solved. And let this be a lesson to anyone who copies their scripts around on a regular basis--make sure all dependent files are copied as well!