Skip to main content
Known Participant
September 19, 2023
Answered

How to pass the arguments from JSX to UXP Script

  • September 19, 2023
  • 3 replies
  • 2075 views

Dear all,

 

I'm writing the code using Extend Script (JSX) and planning to call the UXP script with Arguments, through doScirpt mode

 

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

var argsArray = ["Hariharasudhan", "test1", "test1", "process done"];
 var Processing_connectURL = app.doScript("/Applications/Adobe InDesign 2023/Scripts/Scripts Panel/Workflow_Development/InDesignSource/createsh.idjs", 1431522407, argsArray);
 
//==============================================//
 
But I received the "createsh.idjs" file 
 
//===========================//
const script = require("uxp").script;
alert(script.args);
//===============================//
 
showing alert is empty.
 
Kindly resolve any one, really I will appriciate 
 

 

 

This topic has been closed for replies.
Correct answer sttk3

Could it be that the problem is that you are passing the idjs path as a string during doScript? If you pass File, it might succeed. I have had success with this script.

 

// caller.jsx

var argsArray = ['argString', 20, true] ;
var idjsFile = new File('~/Desktop/callee.idjs') ;
var res = app.doScript(idjsFile, ScriptLanguage.UXPSCRIPT, argsArray, UndoModes.ENTIRE_SCRIPT) ;

 

// callee.idjs

const { app } = require('indesign') ;
const { script } = require('uxp') ;

const alert = (msg) => {
  const dialog = app.dialogs.add() ;
  const col = dialog.dialogColumns.add() ;
  const colText = col.staticTexts.add() ;
  colText.staticLabel = '' + msg ;
  dialog.canCancel = false ;
  dialog.show() ;
  dialog.destroy() ;
  return ;
} ;

alert(script.args[0]) ;
// --> 'argString'

3 replies

sttk3Correct answer
Legend
September 20, 2023

Could it be that the problem is that you are passing the idjs path as a string during doScript? If you pass File, it might succeed. I have had success with this script.

 

// caller.jsx

var argsArray = ['argString', 20, true] ;
var idjsFile = new File('~/Desktop/callee.idjs') ;
var res = app.doScript(idjsFile, ScriptLanguage.UXPSCRIPT, argsArray, UndoModes.ENTIRE_SCRIPT) ;

 

// callee.idjs

const { app } = require('indesign') ;
const { script } = require('uxp') ;

const alert = (msg) => {
  const dialog = app.dialogs.add() ;
  const col = dialog.dialogColumns.add() ;
  const colText = col.staticTexts.add() ;
  colText.staticLabel = '' + msg ;
  dialog.canCancel = false ;
  dialog.show() ;
  dialog.destroy() ;
  return ;
} ;

alert(script.args[0]) ;
// --> 'argString'
Known Participant
September 21, 2023

Dear Sttk3,

 

Thank you, it is working fine, will call with Argument from JSX to IDJS script. 

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

let myInDesign = require("indesign");
let script = require("uxp").script;

let app = myInDesign.app;

 

let ufs = require("uxp").storage.localFileSystem;

const uxpfs = require("uxp").storage;
const shell = require("uxp").shell;

const osname = require("uxp").os;

const osInfo = require('os');

const UserHomeDirsInfo = osInfo.homedir();


let folder = await ufs.getEntryWithUrl("file:"+UserHomeDirsInfo+"/Desktop/StoryBoard_Workflow/Development/TempProcess");

 

 

try {
filePath = await folder.getEntry("connectURL.sh");
}
catch (error){
filePath = await folder.createEntry("connectURL.sh");
}

alert(script.args[0]) ;

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

 

But this is not working for the above code is in the IDJS script. because of the "await" function. It is mandatory to do my code of function.

 

So any other alrernate method is there, along with await functionalities in IDJS script. Mean, with arguments will work with "await" funcitons.

 

Thanks & Regards

Harihara Sudhan T R.,

Robert at ID-Tasker
Legend
September 19, 2023

Just use Label option - on the Document level. 

 

Known Participant
September 20, 2023

Dear Robert,

 

Thank you for giving the solutions. We are also thinking the least options.

Means, we will update the data into the Document Label information (store in document frame or any conditional variables).

from UXP script will read it from the Document and run the UXP script.

Will plan to only execute the UXP script from JSX script.

 

We tried to do for ID-Tasker ... But no support for Mac OS.

 

Kindly let me know any other way to resolve the issue.... really will appriciate.

 

Thanks & Regards

Harihara Sudhan T R

Robert at ID-Tasker
Legend
September 20, 2023

Unfortunately, for Mac users, ID-Tasker is PC only. 

 

John D Herzog
Inspiring
September 19, 2023

I know the 131522407 number is associated with "ScriptLanguage.UXPSCRIPT" in the UXPscript doScript, but I don't know if it would also work with extendscript. I would try to replace it with the actual text and see if that gets it for you.

John D Herzog
Inspiring
September 19, 2023

Are you going to return data from the UXP script? if not, you should not have to make variable declaration for the doScript.