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

How to change working directory in extendscript?

Engaged ,
Jun 20, 2020 Jun 20, 2020

Copy link to clipboard

Copied

Whenever I run a script file, it seems that the working directory is the same directory that the script is located at. However, suppose I want to change the current working directory at run time, including directories which may be located on different drives which may include spaces in their name. How would I do this in ExtendScript?

 

The reason that I ask is because I have ExtendScript running other files that expect to be run from specific directories, and I need to change the current working directory before I run them.

TOPICS
How to , Scripting

Views

638

Translate

Translate

Report

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
LEGEND ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

I'm not clear what you are asking. You should not have any issues by pointing to other folders using their URIs or invoking extra file dialogs. The only thing of concern are potential limitations due to user permissions and other security stuff.

 

Mylenium

Votes

Translate

Translate

Report

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
Engaged ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

Here's an example of what I mean. If I have a Python script that is located in a different directory than the .jsx script and I call it from the .jsx script with something like:

 

system.callSystem("cmd.exe /c pathToMyPythonScript.py"")
 
and the Python script tries to access files using paths that are located in directories specified relative to itself (such as "../template.txt", or "out/template.txt"), then the Python script is unable to find that txt file because when it is run, it's being run with the current working directory set to the .jsx script, not the Python script. I was wondering if there is any native way in ExtendScript to set the current working directory so that when I call the Python script, it is being run from whatever I set the CWD to in ExtendScript.
 
An example of how to do this in Python would be os.chdir(newdirectory). I was simply wondering if there was any way to do it in ExtendScript directly.

Votes

Translate

Translate

Report

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
Community Expert ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

instead of executing the python script directly, you could execute a bat file (or on Mac a shell script) that first changes to that directory and then executes the script.

Mathias Möhl - Developer of tools like BeatEdit and Automation Blocks for Premiere Pro and After Effects

Votes

Translate

Translate

Report

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
LEGEND ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

Sounds convoluted, TBH. Have you considered simply setting system variables/ Py variables? My knowledge of Python is certainly limited outside specific contexts, but I seem to vaguely remeber that it allows to define some custom global variables that it looks up every time the engine is invoked. Perhaps that might simplify the process. Other than that it seems to me you may need to mutually implement code that scans for whether the scripts actually exist in the respective folders and create some kind of temporary file containing a text string containing the path or something like that....

 

Mylenium

Votes

Translate

Translate

Report

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
Engaged ,
Jun 21, 2020 Jun 21, 2020

Copy link to clipboard

Copied

LATEST

I managed to get around it by passing the directory from Extendscript as an argument to the Python script and then changing the directory directly in Python. Not ideal, but it works.

Votes

Translate

Translate

Report

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