Sometimes Broken Script or file renaming
By Dane Butler @Dane_Butler
Hey Chad!
A while back this script was written for me by sam, and for some reason it just......breaks. The conditions never change, but it just doesn't work. IT's frustrating too because it's the script I need to work the most. Is there something that is identifiable in your opinion that would cause it to not find elements that cause it to break?
preformatted text
function checkNameExistsPrompt() {
const nameUsedPrompt = sf.ui.proTools.confirmationDialog.invalidate().children.whoseRole.is("AXStaticText").whoseValue.is("That name is already used by another file.").first;
const fileExistPopup = nameUsedPrompt.exists;
if (fileExistPopup) {
sf.ui.proTools.confirmationDialog.buttons.whoseTitle.is("OK").first.elementClick();
};
return fileExistPopup;
};
function clipNameReplaceCharacter(clipName) {
let n = 0
const clipRenameMenu = sf.ui.proTools.getMenuItem("Clip", "Rename...")
const isClipSelected = clipRenameMenu.isEnabled;
if (!isClipSelected) return;
// Open Name Window
clipRenameMenu.elementClick();
const nameWindow = () => sf.ui.proTools.windows.invalidate().whoseTitle.is("Name").first
nameWindow().elementWaitFor();
if (!nameWindow().exists) return
while (true) {
if (nameWindow().exists) {
const clipNameTextFields = nameWindow().groups.whoseTitle.is("Name").first.textFields.first;
//const clipName = clipNameTextFields().value.invalidate().value
const newClipName = clipName.replace("$", "_EN") + ""
clipNameTextFields.elementSetTextFieldWithAreaValue({ value: newClipName });
nameWindow().buttons.whoseTitle.is("OK").first.elementClick();
if (checkNameExistsPrompt()) {
nameWindow().elementWaitFor();
//clipNameTextFields = nameWindow().groups.whoseTitle.is("Name").first.textFields.first;
clipNameTextFields.elementSetTextFieldWithAreaValue({ value: newClipName + "_" + ++n });
nameWindow().buttons.whoseTitle.is("OK").first.elementClick();
};
nameWindow().elementWaitFor({ timeout: 500, onError: "Continue" });
} else {
break;
};
};
};
function getClipName() {
sf.ui.proTools.getMenuItem("Clip", "Rename...").elementClick();
const nameWindow = sf.ui.proTools.windows.invalidate().whoseTitle.is("Name").first
nameWindow.elementWaitFor();
const clipName = nameWindow.groups.whoseTitle.is("Name").first.textFields.first.value.invalidate().value
nameWindow.buttons.whoseTitle.is("Cancel").first.elementClick();
nameWindow.elementWaitFor({ waitType: "Disappear" });
return clipName
}
const selectTrack = (trackName) => sf.ui.proTools.trackSelectByName({ names: [trackName] });
const selectedTracks = sf.ui.proTools.selectedTrackNames
const topTrack = selectedTracks[0]
const bottomTrack = selectedTracks[1]
selectTrack(bottomTrack);
const bottomTrackClipName = getClipName();
selectTrack(topTrack);
clipNameReplaceCharacter(bottomTrackClipName);
Linked from:
- Kitch Membery @Kitch2023-12-01 19:22:04.008Z
Hi @Dane_Butler
To get help with a Script or macro, please use the Script/Help workflow.
Doing so will gather the information needed to help troubleshoot and hopefully resolve the issue.For more info on how to do this please see the following link. https://soundflow.org/docs/help#script-help.
Thanks in advance.