Running Temp Shell Scripts in OSX (no execution privileges)

Discussion of Photoshop Scripting, Photoshop Actions and Photoshop Automation in General

Moderators: Tom, Kukurykus

russ_c

Running Temp Shell Scripts in OSX (no execution privileges)

Post by russ_c »

I have a python script I need to execute in the OSX Terminal from within a JSX script so I thought I'd have JSX make a quick .sh file and run it. I've discovered that appending .command instead of .sh will make a shell script that can be executed, the only problem is a .command shell script doesn't have the execute attribute set without doing a chmod +x <myFile>

Is there anyway to write a .command shell script from within a JSX script that can be executed?

Furthermore, I've taken some time to look into xbytor's adventures in doing the same thing including a peek at xexec.js, I have to admit I don't fully understand how to use the Exec object...Is there an example of it's use someplace? Also, unless I'm mistaken it seems that xbytor is making a .app and using that to invoke the shell script?! Would love more information on understanding the working parts.

Thanks for any guidance on getting a shell script to execute in OSX,

Russ

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

russ_c

Running Temp Shell Scripts in OSX (no execution privileges)

Post by russ_c »

I'm sorry, seems I missed this:

bb/viewtopic.php?f=9&t=1425&p=5791&hilit=xexec+js#p5791

Unfortunately there seems no simple solution that will work as I desire.
Mikaeru

Running Temp Shell Scripts in OSX (no execution privileges)

Post by Mikaeru »

russ_c wrote:I have a python script I need to execute in the OSX Terminal from within a JSX script
Thanks for any guidance on getting a shell script to execute in OSX,
There is a JSX function called app.system which lets you run a system command the way you would do it in the Terminal application. However, it is undocumented and only available in recent versions of Photoshop (not in CS but OK in CS4 for instance).

If you already have your python script written in a file (/path/to/script.py), you can run it that way:
Code: Select allapp.system ("python /path/to/script.py");
If you prefer to create the python script file on-the-fly from within the JSX script, here is a working example:
Code: Select allvar tempPythonFile = new File (Folder.temp + "/temp.py");
if (tempPythonFile.open ("w"))
{
    tempPythonFile.writeln ('import time');
    tempPythonFile.writeln ('print "Hello, World!"');
    tempPythonFile.writeln ('print time.strftime ("Now is %Y-%m-%dT%H:%M:%S")');
    tempPythonFile.close ();
}
app.system ("python " + tempPythonFile.fsName);
tempPythonFile.remove ();

Please note that the above snippet is not especially useful since its output can only be visualized from the Console application, but it can be helpful for debugging purposes...

HTH,

--Mikaeru
russ_c

Running Temp Shell Scripts in OSX (no execution privileges)

Post by russ_c »

Thanks Mikaeru,

I could swear I tried all the different logical combinations of app.system, app.sys, $.system, and $.sys and searched for them in documentation. An undocumented feature might as well not be a feature, but in this case I'm glad app.system exists. Worked like a charm for my purpose. I'm doing a serious face palm now.

Russ