Skip to main content
Disposition_Dev
Legend
December 26, 2017
Answered

Silent error while trying to execute a batch convert-to-binary

  • December 26, 2017
  • 2 replies
  • 1403 views

I'm attempting to write a BASH function to allow me to batch convert an entire project to jsxbin. The batch script works when i run it directly in extendscript, but when i attempt to run it from the command line it simply fails silently.

in my BASH function, i'm using the following (among several other things that seem to be working just fine):

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd "$compileScript"

the -cmd call to ETSK executes, but does not actually appear to execute the $compileScript compiler, as no files are saved when it's complete. It doesn't throw any errors, it simply doesn't do anything. Again, the same compile_file.jsx script works flawlessly when i run it from ESTK.

Here's the compile_file.jsx code:

function compileBinary()

{

    #target estoolkit#dbg

    // var batchFolder = new Folder("/Volumes/Macintosh HD/Users/will.dowling/Desktop/").selectDlg("Select a folder to batch.");

    var batchFolder = new Folder("/Volumes/Macintosh HD/Users/will.dowling/Desktop/convert_to_binary");

    var destFolder = new Folder("/Volumes/Macintosh HD/Users/will.dowling/Desktop/binary_converted");

    var files = batchFolder.getFiles();

    var contents,compiled,outFile;

    var pat = /\s/g;

    var extPat = /\.js?/;

    var newExt = ".jsxbin";

    for(var x=0,len=files.length;x<len;x++)

    {

        if(files.name.indexOf(".js") === -1)

        {

            continue;

        }

        files.open("r");

        contents = files.read();

        files.close();

        compiled = app.compile(contents);

        compiled = compiled.replace(pat,"");

        compiled = "eval(\"" + compiled + "\")";

        if(files.name.indexOf(".jsx")>-1)

        {

            outFile = new File(destFolder + "/" + files.name)

        }

        else

        {

            outFile = new File(destFolder + "/" + files.name + "xbin" );

        }

        outFile.open("w");

        outFile.write(compiled);

        outFile.close();

    }

}

compileBinary();

Any thoughts on this? It seems that i've followed the example in the scripting reference, but it doesn't seem to work.

This topic has been closed for replies.
Correct answer OMOTI

Hi, williamadowling.

This is my result, for what it's worth.

The batch script was able to work well regardless of deletion of double quotes.

The following is no problem.

macOS 10.12.6

command line:

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd "$compileScript"

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd $compileScript

$ sh w1.sh

$ sh w2.sh

w1.sh:

#!/bin/bash

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd "$compileScript"

w2.sh:

#!/bin/bash

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd $compileScript

2 replies

Disposition_Dev
Legend
September 20, 2019

Ok. So i know this post is old, and i had remarked at one time that the problem had been solved. Until yesterday when it happened again. Suddenly no files were being converted, but there was no error message to indicate that something had gone wrong. Well after poking around for a little while and adding in some rudimentary logging, i realized that the compileScript jsx file was failing when it ran into a .DS_Store file. I had no validation logic in the jsx code to ensure that it was attempting to convert an actual .js(x) file.

So i added in a regex to guarantee the file being processed is correct.

 

Hopefully this information helps someone else at some point.

Disposition_Dev
Legend
September 20, 2019
In case anyone wants to see the full implementation, i threw it up on github. feel free to improve it in any way you see fit. I know it's not pretty, but it works. https://github.com/wdjsdev/automatic_binary_conversion
Ten A
Community Expert
Community Expert
December 26, 2017

Probably, Remove double quart to work like below.

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd $compileScript

Disposition_Dev
Legend
December 27, 2017

i tried that.. i actually added the quotes because it wasn't working without them so I figured perhaps there was an issue with spaces or something in the directory path, but i get the same results either way. =(

OMOTI
OMOTICorrect answer
Inspiring
December 27, 2017

Hi, williamadowling.

This is my result, for what it's worth.

The batch script was able to work well regardless of deletion of double quotes.

The following is no problem.

macOS 10.12.6

command line:

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd "$compileScript"

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd $compileScript

$ sh w1.sh

$ sh w2.sh

w1.sh:

#!/bin/bash

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd "$compileScript"

w2.sh:

#!/bin/bash

compileScript="~/Desktop/compile_file.jsx"

/Volumes/Macintosh\ HD/Applications/Adobe\ ExtendScript\ Toolkit\ CC/ExtendScript\ Toolkit.app/Contents/MacOs/ExtendScript\ Toolkit -cmd $compileScript