open a document from the same folder

Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

i'm trying to open a document from the same folder is the jsx file but its not working 

var fileRef = new File("/fonte tamplate.ait")
    var docRef = app.open(fileRef)
 
TOPICS
Scripting

Views

172

Likes

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

correct answers 2 Correct Answers

Engaged , Apr 13, 2021 Apr 13, 2021
Ok good. Where are you wanting the relative path to point to? The document? If so, then you can get the document path. From memory I think you can do: app.activeDocument.fullName to give you a file reference of the active document. You can then ask for the 'parent' which should give you the folder containing the file (see File object docs). Then ask for (I think) the 'fullName' of the parent to get it's path, then add your own filename, eg. 'fonte tamplate.ait". I hope that works for you.

Likes

Translate

Translate
Adobe Community Professional , Apr 13, 2021 Apr 13, 2021
this line gives you the full path of the current script. From there, you can convert it to a File Object and get it's Parent Folder. alert($.fileName);

Likes

Translate

Translate
Engaged ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Very quick answer, and I'm probably wrong as I can't test it just now... try adding a period before the first slash in the path.

var fileRef = new File("./fonte tamplate.ait");
var docRef = app.open(fileRef);

I can't remember if I've ever used a relative path like this. And I'm not sure what it would be relative to. You could test be writing a text file there perhaps? Also, does your code work with a full path?

Likes

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
Explorer ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

try adding a period and its still not working and yes it does work with a full path like these

 

var fileRef = new File("~/Downloads/fonte tamplate.ait")
  var docRef = app.open(fileRef);  
    

 

but i need to deliver those script to customers so it have to be at the same folder

 

Likes

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 ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

Ok good. Where are you wanting the relative path to point to? The document? If so, then you can get the document path. From memory I think you can do:

 

app.activeDocument.fullName

 

to give you a file reference of the active document. You can then ask for the 'parent' which should give you the folder containing the file (see File object docs). Then ask for (I think) the 'fullName' of the parent to get it's path, then add your own filename, eg. 'fonte tamplate.ait". I hope that works for you.

Likes

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
Adobe Community Professional ,
Apr 13, 2021 Apr 13, 2021

Copy link to clipboard

Copied

LATEST

this line gives you the full path of the current script. From there, you can convert it to a File Object and get it's Parent Folder.

 

alert($.fileName);

Likes

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