Skip to main content
Participant
February 27, 2022
Answered

Extendscript: Project File Save Location

  • February 27, 2022
  • 1 reply
  • 685 views

I am writing a simple (yet seems to be not-so-simple) script that allows me to save a project file with a preset naming convention, in the same folder I opened my template file. 

 

So to be clear - my workflow is that I have a template project file in each new job folder I start. At the beginning of the job, I open this template project up from whatever job folder I am working out of and save it using my script. 

 

When clicking the "Save" button on my script, a new project file with a preset naming convention  will be saved in the same job folder that I initially opened the template project file in. 

 

My question is: How can I get the new file to save in the same fold the template project was opened in? I know I need to replace the "~/Desktop/" in my code below with something else, but I'm not sure what that is. 

My code currently looks like this: 

SaveButton.onClick = function (){

app.project.save(File (["~/Desktop/"ProjectNumber" + "_" + "ProjectName" + "_v001.aep"]));

}

 

I am currently using VS Code with the Extendscript extension. Any help is appreciated.

 

Thanks! 

This topic has been closed for replies.
Correct answer ConstantinMaier

You can get the current file by using:

app.project.file

 

Then use ".parent" to get the parent folder and add your desired file name after it. So, I'd do it like this:

app.project.save(File(app.project.file.parent.fullName.toString().replace(/\\/g, "/") + "/" + "Your File Name.aep"));

1 reply

ConstantinMaier
ConstantinMaierCorrect answer
Inspiring
February 27, 2022

You can get the current file by using:

app.project.file

 

Then use ".parent" to get the parent folder and add your desired file name after it. So, I'd do it like this:

app.project.save(File(app.project.file.parent.fullName.toString().replace(/\\/g, "/") + "/" + "Your File Name.aep"));
_flikAuthor
Participant
February 27, 2022

@ConstantinMaier wow, this worked great! Thank you. I'm so confused on HOW this actually worked, but it's awesome that it did. 

 

Thanks! 

ConstantinMaier
Inspiring
February 27, 2022

Hey, glad to help! 🙂

 

Check out the ExtendScript docs for various file object properties you can work with:
https://extendscript.docsforadobe.dev/file-system-access/file-object.html#file-object-properties

 

Like I said, ".parent" gets the folder of the file.

 

".fullName" will then give us the entire path as a string. That's also why the "toString()" shouldn't even be necessary as I'm just noticing (it's from an old line of code of myself, so I don't know why I added that).

 

".replace(/\\/g, '/')" is so that we convert backslashes on Windows to forward slashes (what we need for scripting). But, testing it out right now, it seems that only ".fsName" (another possible property from the API) produces backslashes and ".fullName" actually produces forward slashes. Originally, I made us of ".fsName" - that's why I needed to put in ".replace(/\\/g, '/')" - but I heard it sometimes can fail, that's why I swiched to ".fullName".

 

So, you could actually simplify the line by just doing this:

app.project.save(File(app.project.file.parent.fullName + "/" + "Your File Name.aep"));

 

For me this works too. Someone may correct me if I'm wrong about any of this. 😉