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

Extendscript: Project File Save Location

Community Beginner ,
Feb 26, 2022 Feb 26, 2022

Copy link to clipboard

Copied

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! 

TOPICS
Expressions , Scripting , User interface or workspaces

Views

277

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 1 Correct answer

Participant , Feb 27, 2022 Feb 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"));

Votes

Translate

Translate
Participant ,
Feb 27, 2022 Feb 27, 2022

Copy link to clipboard

Copied

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"));

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 Beginner ,
Feb 27, 2022 Feb 27, 2022

Copy link to clipboard

Copied

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

 

Thanks! 

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
Participant ,
Feb 27, 2022 Feb 27, 2022

Copy link to clipboard

Copied

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. 😉

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 Beginner ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

@ConstantinMaier that's awesome! I really appreciate it. Actually...follow up question. is there a way to call the Increment and Save function in after effects? So in theory I should be able to just copy this button function to a new button, but then have the new button increment and save? 

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
Participant ,
Feb 28, 2022 Feb 28, 2022

Copy link to clipboard

Copied

LATEST

Not directly in the API but you can call to execute the menu command ID of "Increment and Save". You can find the command ID like this:

alert(app.findMenuCommandId("Increment and Save"));

 

It returns 3088. So just call "Increment and Save" like this:

app.executeCommand(3088);

 

Another option would be to write a function to increment the project file name yourself and then save the file as such. But you'll have to figure out how to write it and if you don't need any more customization than the native "Increment and Save" offers, I'd say just go with using "app.executeCommand()". 😉

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