Answer in OP.
I've made a detailed video going through the code and how I approach creating such a script (20 min). It will be relevant if you're new to scripting and wanna understand it better. The script can of course be adapted to lots of applications:
https://youtu.be/asfMJhA1aTE
This is the finished code from the video. It will make sure that the action is only performed when it's a MIDI track.
var app = sf.ui.nuendo.exists ? sf.ui.nuendo : sf.ui.cubase;
var cubendo = app.title.value;
var midiOutput = 'IAC Driver toIcon' // put the name of your desired MIDI Output
sf.clipboard.setText({ text: midiOutput })
app.appActivateMainWindow();
if (!app.getWindowWithTitleStartingWith('Channel Settings').exists) {
sf.ui.cubendo.performAction({
categoryName: "Edit",
actionName: "Edit Channel Settings",
});
sf.wait({ intervalMs: 50 })
}
for (var i = 0; i < 6; i++) { // Put the Amount of MIDI outputs you wanna route
var isMidiTrack = app.getWindowWithTitleStartingWith('Channel Settings').title.value.match(']') == null;
var isNotFolder = app.getMenuItem('Project', 'Track Versions', 'New Version').isEnabled
if (isMidiTrack && isNotFolder) {
app.getWindowWithTitleStartingWith(cubendo).mouseClickElement({ relativePosition: { x: 50, y: 375 } })
sf.keyboard.press({ keys: 'cmd+v,enter' })
}
else i = i - 1
sf.ui.cubendo.performAction({
categoryName: "Project",
actionName: "Select Track: Next",
});
sf.wait({ intervalMs: 1000 })
}
A simplified version of the script (runs faster) but doesn't check what type of track it's on. Only use that if you only have midi tracks after each other:
var app = sf.ui.nuendo.exists ? sf.ui.nuendo : sf.ui.cubase;
var cubendo = app.title.value;
var midiOutput = 'IAC Driver toIcon' // put the name of your desired MIDI Output
sf.clipboard.setText({ text: midiOutput })
app.appActivateMainWindow();
for (var i = 0; i < 6; i++) { // Put the Amount of MIDI outputs you wanna route
app.getWindowWithTitleStartingWith(cubendo).mouseClickElement({ relativePosition: { x: 50, y: 375 } })
sf.keyboard.press({ keys: 'cmd+v,enter' })
sf.ui.cubendo.performAction({
categoryName: "Project",
actionName: "Select Track: Next",
});
sf.wait({ intervalMs: 50 })
}
.
(afterwards I realized you can do this another way internally in Cubase, but it doesn't make these scripts less valid as a resource)
- In reply toJesperA⬆:Jesper Ankarfeldt @JesperA2019-11-01 21:07:29.951Z
As experienced in the video I had to add a delay (sf.wait) in order for the script to successfully read when it was a folder. Turns out it's probably because Cubase/Nuendo doesn't update its Menus more then once a second.
So instead of checking the menu you can just check if the Channel Settings window name changes, cause if it doesn't, you know that it's a folder track. So the script will look like this instead:
var app = sf.ui.nuendo.exists ? sf.ui.nuendo : sf.ui.cubase; var version = app.shortVersionString; var cubendo = app.title.value; var midiOutput = 'IAC Driver to' sf.clipboard.setText({ text: midiOutput }) app.appActivateMainWindow(); if (!app.getWindowWithTitleStartingWith('Channel Settings').exists) { sf.ui.cubendo.performAction({ categoryName: "Edit", actionName: "Edit Channel Settings", }); sf.wait({ intervalMs: 50 }) } var oldName = '' for (var i = 0; i < 3; i++) { var isMidiTrack = app.getWindowWithTitleStartingWith('Channel Settings').title.value.match(']') == null; var isNotFolder = false var newName = app.getWindowWithTitleStartingWith('Channel Settings').title.value; if (oldName != newName) { isNotFolder = true oldName = newName } if (isMidiTrack && isNotFolder) { app.getWindowWithTitleStartingWith(cubendo).mouseClickElement({ relativePosition: { x: 50, y: 375 } }) sf.keyboard.press({ keys: 'cmd+v,enter' }) } else i = i - 1 sf.ui.cubendo.performAction({ categoryName: "Project", actionName: "Select Track: Next", }); sf.wait({ intervalMs: 50 }) }
- Progress