Skip to main content
Participating Frequently
Mar 13, 2024 3:10 PM UTC
Question

Run script when opening an AE project

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 is closed to new replies. Start a new post to keep the conversation going.

4 replies

Alex White
Legend
Mar 13, 2024 3:59 PM UTC

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

 

Translate
Participating Frequently
Mar 13, 2024 4:12 PM UTC

Thanks! But can I use this code in expression?

Translate
Alex White
Legend
Mar 13, 2024 4:30 PM UTC

Nope, unfortunately

Translate