Copy link to clipboard
Copied
Can I run a script when I open a AE project?
I created some scripts to automate diferent projects, and was wondering if I can run specific script for each project. Maybe some call with extended script/expression?
I can't use the "startup script" because needs administrator's autorization.
Thank you!
Copy link to clipboard
Copied
There is no hook/method available so the best you can do is monitor the project name via a timer and apply certain functions depending on the name. Here is a rought example:
// Global variables
var previousProjectPath = "";
// Function to check project path and execute functions
function checkProjectPath() {
var currentProjectPath = app.project.file ? app.project.file.fsName : "";
if (currentProjectPath !== previousProjectPath) {
previousProjectPath = currentProjectPath;
if (currentProjectPath !== "") {
var projectName = app.project.file.name.replace(/\.aep$/, "");
switch (projectName) {
case "Project1":
executeProject1Functions();
break;
case "Project2":
executeProject2Functions();
break;
// Add more cases for different project names
default:
alert("Unknown project: " + projectName);
}
}
}
}
// Function to execute specific functions for Project1
function executeProject1Functions() {
// Add your custom functions for Project1 here
alert("Project1 functions executed");
}
// Function to execute specific functions for Project2
function executeProject2Functions() {
// Add your custom functions for Project2 here
alert("Project2 functions executed");
}
// Start the scheduled task
app.scheduleTask("checkProjectPath()", 3000, true);
Copy link to clipboard
Copied
Thanks! But can I use this code in expression?
Copy link to clipboard
Copied
Nope, unfortunately
Copy link to clipboard
Copied
I just found a workaround by putting the script in the local user startup folder:
C:\Users\xxx\AppData\Roaming\Adobe\After Effects\22.6\Scripts\Startup
I thought that only the main directory of After had the Startup Scripts folder.
Thanks for the advice!