Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
6

Run shell file in UXP Script

Explorer ,
Aug 04, 2023 Aug 04, 2023

Dear All,

 

I'm unable to run / execute the external shell file using through UXP scripts. We tried to use the below reference but unable to do that through UXP. 

 

Actually, I created the shell file (.sh) in local folder. I have to run the shell file through terminal.

 

https://developer.adobe.com/xd/uxp/uxp/reference-js/Modules/shell/Shell/

 

We tried to include the normal File.execute into UXP then, that also showing the File error.

 

Kindly can anyone help me on this and will appriciate 🙂

 

Thanks & Regards,

Harihara Sudhan T R.,

 

TOPICS
Scripting , UXP Scripting
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Aug 04, 2023 Aug 04, 2023

Then, call which node in the terminal. Once you get the full location for Node bin, use it in your bash command

instead of 

node .

use 

/whatever/path/which/returned/to/node .

Translate
Explorer ,
Aug 04, 2023 Aug 04, 2023

The linked page is pretty explicite. The module shell in the context of UXP seems to offer two methods only. They mainly consists in opening locations, not executing commands.

If I test shell.openPath, then it behaves as expected.

So if you want a bash file to be ran, you need a different approach. UXP doesn't seem to include the exec or spawn module. However you can use doScript to run an applescript that runs the bash file.

The following seems to do the trick:

var scpt = 'do shell script "bash /path/to/file/cmd.sh"';
app.doScript(scpt, ScriptLanguage.APPLESCRIPT_LANGUAGE);

HTH

Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2023 Aug 04, 2023

Dear Loic,

 

I tried to call the Node script from Bash file :

//================================

Script File :

var scpt = 'do shell script "bash  /Desktop/HTMLDownload/htmlcalling.sh"';
app.doScript(scpt, ScriptLanguage.APPLESCRIPT_LANGUAGE);
//============================
 
htmlcalling.sh - file
//=========================
cd "/Desktop/HTML_Node/"
node index.js
//=======================
 
I tried to run the script and it showing the error.
"
Exception has occurred: 127
/Desktop/HTMLDownload/htmlcalling.sh: line 2: node: command not found"
 
But I tried in terminal with "bash  /Desktop/HTMLDownload/htmlcalling.sh" it is running perfectly. 
 
So, Please help me how to resolve this critical issue. or will open the terminal and run the bash file ....?
 
Kindly need yourn help
 
Thanks & Regards
Harihara Sudhan T R.,
 
app.doScript(scpt, ScriptLanguage.APPLESCRIPT_LANGUAGE);
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2023 Aug 04, 2023
quote
/Desktop/HTMLDownload/htmlcalling.sh: line 2: node: command not found"

By @Harihara28692478zxj6

Excuse me for asking but is Node actually installed on the machine? Given the message you get, I doubt about it. But if yes, you may simply have an environment variable issue:

https://stackoverflow.com/questions/18130164/nodejs-vs-node-on-ubuntu-12-04
Does the same command works in the terminal?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2023 Aug 04, 2023

Dear Loic,

Thank you for your support!

1. Yes, I installed NodeJS in my mac OS. 

2. I runned the below command with in the terminal manually

//=====================================

username@<MachineName> ~ % bash /Desktop/HTMLDownload/htmlcalling.sh

//=====================================

It is running perfectly and deliver the output file which I mentioned path in the nodeJS

So that, any idea to run and fixing this issue.

Thanks & Regards

Harihara Sudhan T R.,

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 04, 2023 Aug 04, 2023
LATEST

Then, call which node in the terminal. Once you get the full location for Node bin, use it in your bash command

instead of 

node .

use 

/whatever/path/which/returned/to/node .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines