Where am I ? Lost in scriptation

Hello.

I got a simple question : is there a way to get the current script path ?

I found the “app.activeScript” statement in the documentation but it returns a Promise and the final value is an curious (useless…?) object.
__filename contains the script name but without the path.

I check natives modules (fs, uxp, storage) but none seems able to help me…

Thank you for your help.
Best.
Tristan.

If you write plugin… you can convert plugin:// into native path to get location of plugin directory. Not sure about scripts.

2 Likes

This script was able to get the path. But whether it can access files based on that is another matter.

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

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

const scriptPath = (await app.activeScript).nativePath ;
alert(scriptPath) ;
1 Like

Thanks you for your answers !

@Jarda : actually I use scripts that can be executed from many places that’s why I try to get the script location.

@sttk3 : the “await app.activeScript” returns an object containing 3 properties :

{ 
    "name":"",
    "type":"folder",
    "nativePath":"/"
}

It seems it has been the solution to get the current script path but not anymore.
It just always gives a “/”…

@Tristan I wonder why that is. Tried InDesign 2023-2025 and they all returned successful paths.

It could be for security reasons. Old ExtenScripts are security nightmare :smiley:

In plugins you need to add permissions to allow plugin visit any location in your PC. Because there is permission in manifest then PS or InDesign can ask you for consent. Scripts cannot have manifest.

Nobody would like script searching for passwords.txt on the user desktop and sending it to the internet.

@Jarda Yes, I agree. It is a regular behavior in the UXP philosophy that the path should not be accessible.

Photoshop is true to that philosophy, but with InDesign it no longer seems to care about that.

Hey, when I was eating an idea comes to me : maybe I can’t get the script path because I execute it through the UXP dev tool ?!?

Back to my office I tried without UDT and eurêka, now I can get the full path with app.activeScript !

I have to keep in mind that the context could be different between direct execution and the debugger !

Thank you again for your help !!
BR.
Tristan

2 Likes

@Tristan At the risk of asking a stupid question . . . how are you running extendscript or uxp scripts that are located outside of InDesign’s Scripts Panel folder (I didn’t know you could)?

Philip

Hi Philip.

In my company we have some scripts (JSX and soon UXP) that are located to the startup scripts folder in the inDesign application.

And sometimes they are located to the Script Panel folder.

Soon we will also have to make some scripts for InDesign Server, I don’t know yet where scripts will have to be located but I guess we will be happy to be able to check their location with the activeScript method :wink:

Ah, I see. I thought maybe you had them somewhere outside the folders that InDesign provides. In the applescript world (that I am most familiar with) you can have your scripts anywhere, but I had not found an equivalent using extendscript or now uxp scripts . . . I’m sure someone will correct me if it is possible! :wink:

@philipbuckley It can be executed via AppleScript do script. And either in VBS or from ExtendScript with the equivalent command.

tell application id "com.adobe.InDesign"
	set target_script to "Macintosh HD:Users:username:Desktop:script_path.idjs" as alias
	do script target_script language uxpscript with arguments {} undo mode entire script
end tell

@sttk3 Thanks very much. That’s very useful.

1 Like