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

Passing file path from JS to python

Contributor ,
Jan 14, 2022 Jan 14, 2022

Hi All,

 

I'm trying to pass the filepath  as argument from the javascript to python script. Is it possible to pass the arugment from the indesign script to python code? Any help is much appreciated.

Thanks

 

 

TOPICS
Scripting
670
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
Community Expert ,
Jan 14, 2022 Jan 14, 2022

There's probably a better way but I'd probably just save the string to a tmp file and read that tmp file in the Python. 

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
Contributor ,
Jan 14, 2022 Jan 14, 2022

Thanks brian! how to save the string in the tmp file?

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
Community Expert ,
Jan 14, 2022 Jan 14, 2022
    var myFileStr = "C:/My/File/Path";
    var f = File(Folder.temp + "/tempFileName.txt");
    f.encoding = "UTF-8";
    f.open("w");
    f.write(myFileStr);
    f.close();
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
Community Expert ,
Jan 14, 2022 Jan 14, 2022

In addition to what @brian_p_dts mentioned, I would like to ask a followup question, how are you connecting InDesign and Python? If you share what you are currently doing we could find a cleaner way perhaps. For one I could think that Python could access InDesign API via COM(Python should have a library for doing so), if so then you could take much of your code totally in Python and JS vanishes from the equation or you could use a mix of Python COM interface with app.doScript. If MAC comes into picture something similiar could be worked out there too with Applescript and Python. However, as said if you share what you have done/achieved till now then we can brainstorm on the options, else what Brain has said is the simplest and surest way to make it work

-Manan

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
Contributor ,
Jan 15, 2022 Jan 15, 2022
LATEST

Thanks Manan! My existing Script was developed in JS. Now I developed the new python script functionlity for deleting the elements in HTML file using xpath. My requirement is to pass the HTML file path from JS UI to Python script.

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