Command not found issue for a script that runs from keyboard trigger.
Title
Command not found issue for a script that runs from keyboard trigger.
What do you expect to happen when you run the script/macro?
This script grabs selected audio clips and gathers unique channel names. Then a user prompt to choose where each unique channel gets copied to.
Are you seeing an error?
What happens when you run this script?
No problems running script from a keyboard trigger. I created a button on a surface and get a command not found error. I place a screenshot on the forum..
My usual ProTools surface I added as a button command. It shows up on the editor, but not on my iPhone showing the surface and won't run the script if I press the empty button.
How were you running this script?
I used a keyboard shortcut within the target app
How important is this issue to you?
5
Details
{ "inputExpected": "This script grabs selected audio clips and gathers unique channel names. Then a user prompt to choose where each unique channel gets copied to.", "inputIsError": false, "inputWhatHappens": "No problems running script from a keyboard trigger. I created a button on a surface and get a command not found error. I place a screenshot on the forum..\n\nMy usual ProTools surface I added as a button command. It shows up on the editor, but not on my iPhone showing the surface and won't run the script if I press the empty button.", "inputHowRun": { "key": "-Mpfwh4RkPLb2LPwjePT", "title": "I used a keyboard shortcut within the target app" }, "inputImportance": 5, "inputTitle": "Command not found issue for a script that runs from keyboard trigger." }
Source
// Make Pro Tools active.
sf.ui.proTools.appActivateMainWindow();
// Ask if ready to go
try { //Asks if ready, on cancel: re-displays Scene&Take
sf.interaction.displayDialog({
prompt: "Please have clips selected for track layout",
buttons: ['Ready', 'Cancel'],
defaultButton: 'Ready',
executionMode: "Foreground",
giveUpAfterSeconds: 5,
// cancelButton: "Not Ready",
onCancel: "ThrowError",
})
} catch (err) {
// Make sure Scene&Take are being shown.
sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is("Clip List").first.popupMenuSelect({
menuPath: ["Show", "Scene and Take"],
targetValue: "Enable"
});
throw 0;
};
// var GroupChoice="";
const trackGroupChoice = ["DX A", "DX B", "SFX", "BG", "MX"];
// // // try {
// Asks if ready, on cancel: re-displays Scene&Take
const selectedGroups = sf.interaction.selectFromList({
items: trackGroupChoice, // Put in an array of track names
defaultItems: [trackGroupChoice[0]],
allowMultipleSelections: false,
prompt: "Choose which track types to send to.",
title: "Choosing Destination tracks.",
oKButton: "OK",
cancelButton: "Cancel",
onCancel: "Abort",
executionMode: "Foreground",
}).list;
]
var GroupChoice = JSON.stringify(selectedGroups).replace(/[[\]]/g, ''); //takes away brackets around name
GroupChoice = GroupChoice.replace(/\"/g, "");
var trackMapChoice = [];
//Assign group tracks
switch (GroupChoice) {
case "DX A":
trackMapChoice = ["A_boom 1", "A_boom 2", "A__dx 1", "A__dx 2", "A__dx 3", "A__dx 4", "A__dx 5", "A__dx 6"];
break;
case "DX B":
trackMapChoice = ["B_boom 1", "B_boom 2", "B__dx 1", "B__dx 2", "B__dx 3", "B__dx 4", "B__dx 5", "B__dx 6"];
break;
case "SFX":
trackMapChoice = ["FX mono 1", "FX mono 2", "FX mono 3", "FX mono 4", "FX mono 5", "FX mono 6"];
break;
case "BG":
trackMapChoice = ["TO BE DEVELOPED"];
break;
case "MX":
trackMapChoice = ["TO BE DEVELOPED"];
break;
default:
trackMapChoice = ["A_boom 1", "A_boom 2", "A__dx 1", "A__dx 2", "A__dx 3", "A__dx 4", "A__dx 5", "A__dx 6"];
break;
}
// Make sure Channel Names is being shown.
sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is('Clip List').first.popupMenuSelect({
menuPath: ["Show", "Channel Name"],
targetValue: "Enable"
});
// Make sure Scene&Take are hidden. Easier to derive channel name. Gets turned back on ending.
sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is("Clip List").first.popupMenuSelect({
menuPath: ["Show", "Scene and Take"],
targetValue: "Disable"
});
// Get Channel Names
const selectedClips = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first.children.whoseRole.is("AXRow").allItems.map(row =>
row.children[1].children.first.value.value).filter(c => c.startsWith('Selected. ')).map(l =>
l.split("(")[1]).map(n => n.replace(/["\"]/g, '')).map(o => o.split(")")[0]);
// alert("SelectedClips: " + selectedClips);
// Removes duplicate Channel Names and creates a new array set.
const finalChannelNames = [...new Set(selectedClips)];
const finalChannelNamesLength = finalChannelNames.length.toString();
// const trackMapChoice = ["A_boom 1", "A_boom 2", "A__dx 1", "A__dx 2", "A__dx 3", "A__dx 4", "A__dx 5", "A__dx 6"];
var arrTrackName = [];
var STRSelectedClipsCurrent = "";
var selectedClipsCount = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first.children.whoseRole.is("AXRow").allItems.map(row =>
row.children[1].children.first.value.value).filter(c => c.startsWith('Selected. '));
let i = 0;
while (i < finalChannelNames.length) {
const selectedOptions = sf.interaction.selectFromList({
items: trackMapChoice, // Put in an array of track names
defaultItems: [trackMapChoice[0]],
allowMultipleSelections: false,
prompt: "Please select track for Channel Name of: \n\n " + finalChannelNames[i] + "\n",
title: "Clips with Channel Name of " + finalChannelNames[i] + " routing",
oKButton: "Go Forth",
cancelButton: "Cancel",
onCancel: "Abort",
executionMode: "Foreground",
}).list;
// log(selectedOptions);
arrTrackName[i] = JSON.stringify(selectedOptions).replace(/[[\]]/g, ''); //takes away brackets around name
arrTrackName[i] = arrTrackName[i].replace(/\"/g, "");
// alert("NEWEST CHANGE ==> arrTrackName[i]: " + arrTrackName[i]);
i++; //step up 1 on iteration
}
// New step thru code from AAF layout template hk v1 template mono
var numTrackCount = sf.ui.proTools.selectedTrackCount;
var orgTrackName = sf.ui.proTools.selectedTrackNames;
var numTrackCountSTR = String(numTrackCount);
var ReturnToTrackName = sf.ui.proTools.selectedTrackNames[0];
/////// ------------ Define function to copy
function CopyAndMoveClips() {
// Get ChannelName of current clip
var SelectedClipsCurrent = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first.children.whoseRole.is("AXRow").allItems.map(row =>
row.children[1].children.first.value.value).filter(c => c.startsWith('Selected. ')).map(l =>
l.split("(")[1]).map(n => n.replace(/["\"]/g, '')).map(o => o.split(")")[0]);
STRSelectedClipsCurrent = JSON.stringify(SelectedClipsCurrent[0]).replace(/]|[[]/g, ''); //takes away brackets around name
STRSelectedClipsCurrent = STRSelectedClipsCurrent.replace(/\"/g, ""); //takes away quotes
// alert("Should not have quotes: STRSelectedClipsCurrent: " + STRSelectedClipsCurrent);
let CurrentChNameIndex = finalChannelNames.indexOf(STRSelectedClipsCurrent);
// finalChannelNames is the array containing all unique Channel Names
log("Channel Name: " + STRSelectedClipsCurrent + " " + "\nSelected clips moving to: " + arrTrackName[CurrentChNameIndex] + " ");
//Counts # of clips
let clipsTable = sf.ui.proTools.mainWindow.tables.whoseTitle.is('CLIPS').first;
//Copy the current clip to the clipboard
sf.keyboard.press({ keys: 'cmd+c' });
//Mute the current clip
sf.keyboard.press({ keys: 'cmd+m' });
//Go to our target track
sf.ui.proTools.trackSelectByName({
deselectOthers: true,
names: [arrTrackName[CurrentChNameIndex]]
});
// Waiting: gives ProTools time to select track
sf.wait({
intervalMs: 500,
});
//Check that destination track is empty
// NEED TO CHANGE HOW THIS WORKS
var DESTselectedClipCount = clipsTable.getElements("AXSelectedRows").allItems.length;
if (DESTselectedClipCount > 0) {
// handles if clips are in the way
sf.interaction.displayDialog({
prompt: "Did not copy.\n\n There is a clip in the way on the destination track.",
buttons: ['Done'],
defaultButton: 'Done',
executionMode: "Foreground",
giveUpAfterSeconds: 9
});
//Unmute the current clip
sf.keyboard.press({ keys: 'cmd+m' });
// Make sure Scene&Take are being shown.
sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is("Clip List").first.popupMenuSelect({
menuPath: ["Show", "Scene and Take"],
targetValue: "Enable"
});
//Stops
throw 0;
}
//Go to target track
sf.ui.proTools.trackSelectByName({
deselectOthers: true,
names: [arrTrackName[CurrentChNameIndex]]
});
// Waiting: gives ProTools time to select track
sf.wait({
intervalMs: 500,
});
//Paste the clip to target track
sf.ui.proTools.menuClick({
menuPath: ['Edit', 'Paste']
});
// orgTrackName
//Go to our target track
sf.ui.proTools.trackSelectByName({
deselectOthers: true,
names: [ReturnToTrackName]
});
};
if (numTrackCount > 1) {
sf.interaction.displayDialog({
prompt: 'Too many AAF tracks selected.',
buttons: ['OK'],
defaultButton: 'OK'
});
throw 0;
} else {
// call CopyAndMoveClips() function
// CopyAndMoveClips();
function ProcessClips() {
sf.ui.proTools.clipDoForEachSelectedClip({
action: CopyAndMoveClips
});
}
ProcessClips();
};
// Make sure Scene&Take are being shown.
sf.ui.proTools.mainWindow.popupButtons.whoseTitle.is("Clip List").first.popupMenuSelect({
menuPath: ["Show", "Scene and Take"],
targetValue: "Enable"
});
sf.interaction.displayDialog({
prompt: 'Moved:\n ' + selectedClips + "\nTo: \n" + arrTrackName + "\n\n " + (selectedClipsCount.length) + " total clips.",
buttons: ['Done'],
defaultButton: 'Done',
executionMode: "Foreground",
giveUpAfterSeconds: 5
});
throw 0;
Links
User UID: JKOE9oojo5S8UvR5qkLiXn8zJ9l2
Feedback Key: sffeedback:JKOE9oojo5S8UvR5qkLiXn8zJ9l2:-Nn7Xq8lN2fNUsjirt5E
Feedback ZIP: q9y7K+X8brhDsUKytPparzrDhaa5PNp+LrDyDZuqlfWK/RfU3iTXEKnvx2xwD9r5cVu3XW/kF67bZhFlmFFY3ma5nYCc32RXfZ5+KA6Zn0izhMnVbx/xqWvpgk4hRMwXu6v79d3kN3ydhUddfCkChFk5+gQ/iYaRYayZHo3866m7JmbVF9fXDBLfKBjSkv/SP33yvF9+RGJjNyY0xBkUFx21qjHQm8oAoUg6hvJdqYGPYYT5dQY2TM5YZj5PyEJdwCKZeQJUdJa2CiIiuIMn78P1S7FgHwE/6dJPZd/wtrZQ3m1mu+L1Petcl3XASxqifDBlDWPb13EUL0BkVjuIAESVwsTasWmZj/BWz49jcVo=