Skip to main content
Participating Frequently
March 13, 2024
Question

Run script when opening an AE project

  • March 13, 2024
  • 1 reply
  • 816 views

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!

This topic has been closed for replies.

1 reply

Alex White
Legend
March 13, 2024

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

 

Participating Frequently
March 13, 2024

Thanks! But can I use this code in expression?

Alex White
Legend
March 13, 2024

Nope, unfortunately