Skip to content

Instantly share code, notes, and snippets.

@moelle89
Created January 10, 2024 15:05
Show Gist options
  • Save moelle89/b3c747f501b058b4c04f1a1ac9719a93 to your computer and use it in GitHub Desktop.
Save moelle89/b3c747f501b058b4c04f1a1ac9719a93 to your computer and use it in GitHub Desktop.
ask for name
function askForName(type, duration) {
var ptext = 'Please enter a name for the template\n (without spaces, special characters, capital letters, or dashes):';
var name = showDialogWindow(ptext);
if (name) {
var isValid = /^[a-z0-9_]+$/.test(name);
if (isValid) {
var newName = type + name;
var worked = "";
if (type = "post_") { worked = createCompSet(name, type, duration) }
else { worked = renameCompositions(name, type)};
// Save Project with New Name in Same Path
// Get the current project file
if (worked) {
var currentProject = app.project.file;
// Check if a project is open
if (currentProject) {
// Get the current project's path
var projectPath = currentProject.parent.fsName;
// Prompt the user for a new project namemusch
var newProjectName = newName;
// Check if the user entered a name
if (newProjectName) {
// Create the new project file path
var newProjectPath = projectPath + "/" + newProjectName + ".aep";
var newProjectFile = new File(newProjectPath);
// Save the project with the new name
app.project.save(newProjectFile);
// Alert the user that the project has been saved
alert("Project saved as: " + newProjectName);
// Optional: Redraw the UI to reflect the changes
} else {
// Alert the user that no name was entered
alert("No project name entered. The project was not saved with a new name.");
}
} else {
// Alert the user that no project is open
alert("No project is currently open.");
}
} else {
alert("Invalid name! The name should only contain lowercase letters, numbers, and underscores (_) with no spaces, special characters, capital letters, or dashes.");
if (result !== null) {
if (duration) { worked = createCompSet(newName, type, duration) } else { worked = renameCompositions(name, type) };
} else {
// User canceled the input, handle accordingly or exit
alert("User canceled the input.");
}
}
} else {
alert("Invalid name! The name should only contain lowercase letters, numbers, and underscores (_) with no spaces, special characters, capital letters, or dashes.");
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment