Import Audio Code Trouble
I am having trouble with my code. I am new to coding so I use very simple language. My goal is to import audio, use the find command, paste command, move down to second folder, highlight all the stems, and then press copy/convert (i used cmd+c) and then enter enter. Again I am new so this is probably really simple code. Thank you for the help.
sf.wait({
intervalMs: 400,
});
sf.keyboard.press({
keys: "shift+cmd+I",
fast: true,
});
sf.wait({
intervalMs: 400,
});
sf.keyboard.press({
keys: "cmd+f",
fast: true,
});
sf.wait({
intervalMs: 400,
});
sf.keyboard.type({
text: "/Users/tiernan/Documents/IN PROGRESS SESSION/T112-G001-F001-K001-ARTIST-SONG"
})
});
sf.wait({
intervalMs: 400,
});
sf.keyboard.press({
keys: "right",
fast: true,
});
sf.wait({
intervalMs: 400,
});
sf.keyboard.press({
keys: "down",
fast: true,
});
sf.wait({
intervalMs: 400,
});
sf.keyboard.({
keys: "shift+down*(256)",
fast: true,
});
sf.wait({
intervalMs: 400,
});
- Nathan Salefski @nathansalefski
If you quickly edit this post, click </> above where you type and copy the code where it says "preformatted text", it'll appear like the text below and be much easier to read.
preformatted text
Nathan Salefski @nathansalefski
Here is what I believe you would want. The issue would be this would only open this exact file path and import that audio.
//Activate Pro Tools sf.ui.proTools.appActivate(); //File, Import, Audio sf.ui.proTools.menuClick({ menuPath: ["File","Import","Audio..."], }); //Define Import Audio Window const openWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; //Wait for 'Open' Window openWin.elementWaitFor(); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for Open Window openWin.sheets.first.elementWaitFor(); //Set Destination openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: "/Users/tiernan/Documents/IN PROGRESS SESSION/T112-G001-F001-K001-ARTIST-SONG", }); //Press Return sf.keyboard.press({ keys: "return", }); //Select All sf.keyboard.press({ keys: "cmd+a", }); //Click Open openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Wait sf.wait(); //Click Open on Second Window sf.ui.proTools.windows.whoseTitle.is("Open").first.buttons.whoseTitle.is("Open").first.elementClick();
- OOwen Granich-Young @Owen_Granich_Young
@Nathan_Salefski how about a sf.interaction to define the value instead? Put this at the top of the code:
const importDirectory = sf.interaction.selectFolder({ prompt : `Select Folder to Import All Audio`, }).path;
And then change your code line 16 to read :
openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: importDirectory, });
Untested.... but should in theory prompt you for the folder and then run the script as is...
Nathan Salefski @nathansalefski
I had no idea you could do that, that's awesome. This should work for both Copying and Converting the imported audio
//Activate Pro Tools sf.ui.proTools.appActivate(); // Prompt for Folder with Option To Cancel let importDirectory = sf.interaction.selectFolder({ prompt : `Select Folder to Import All Audio`, }).path; //File, Import, Audio sf.ui.proTools.menuClick({ menuPath: ["File","Import","Audio..."], }); //Define Import Audio Window const openWin = sf.ui.proTools.windows.whoseTitle.is('Open').first; //Wait for 'Open' Window openWin.elementWaitFor(); //Open 'Go' Sheet sf.keyboard.type({ text: '/' }); //Wait for Sheet Window openWin.sheets.first.elementWaitFor(); //Set Destination openWin.sheets.first.textFields.first.elementSetTextAreaValue({ value: `${importDirectory}`, }); //Press Return sf.keyboard.press({ keys: "return", }); //Wait for Window to Disappear openWin.sheets.first.elementWaitFor({ waitType: "Disappear" }) //Select All sf.keyboard.press({ keys: "cmd+a", }); //Click Open openWin.buttons.whoseTitle.is('Open').first.elementClick(); //Click Open on Second Window if Necessary if (sf.ui.proTools.windows.whoseTitle.is("Open").exists) { //Click Open on Second Window sf.ui.proTools.windows.whoseTitle.is("Open").first.buttons.whoseTitle.is("Open").first.elementClick(); };
- In reply toOwen_Granich_Young⬆:TTiernan Cranny @Tiernan_Cranny
thnak you so much
Nathan Salefski @nathansalefski
Absolutely. Let me know if it works out for ya
- OIn reply toTiernan_Cranny⬆:Owen Granich-Young @Owen_Granich_Young
Can you post a video of you doing your workflow manually? Helps people understand the end goal. There are a number of things you can do to improve this script for sure. Just want to make sure we understand the final result you're looking for.
- TTiernan Cranny @Tiernan_Cranny
will do
- In reply toTiernan_Cranny⬆:Eric Huergo @Eric_Huergo
Sup' Tiernan - quick tip for inputting code on the forums. When you're typing in the text there's a button above the textbox that looks like a "</>". Click that and replace the line 'preformatted text' with your code. After that, your code will look nice and organized like so:
sf.wait({ intervalMs: 400, }); sf.keyboard.press({ keys: "shift+cmd+I", fast: true, }); sf.wait({ intervalMs: 400, }); sf.keyboard.press({ keys: "cmd+f", fast: true, }); sf.wait({ intervalMs: 400, }); sf.keyboard.type({ text: "/Users/tiernan/Documents/IN PROGRESS SESSION/T112-G001-F001-K001-ARTIST-SONG" }) }); sf.wait({ intervalMs: 400, }); sf.keyboard.press({ keys: "right", fast: true, }); sf.wait({ intervalMs: 400, }); sf.keyboard.press({ keys: "down", fast: true, }); sf.wait({ intervalMs: 400, }); sf.keyboard.({ keys: "shift+down*(256)", fast: true, }); sf.wait({ intervalMs: 400, });
What I gather you're trying to do from the outline of your script is the following:
- Wait 400ms
- Shift+Cmd+I (Import Audio)
- Wait 400ms
- Cmd+F (Find)
- Wait 400ms
- Type the string "/Users/tiernan/Documents/IN PROGRESS SESSION/T112-G001-F001-K001-ARTIST-SONG"
- Wait 400ms
- Press the "right" arrow key
- Wait 400ms
- Press the "down" arrow key
- Wait 400ms
- Press Shift+Down 256 times
- Wait 400ms
Generally speaking, what you're trying to do is simple but there are a few errors in your process. These are the errors I see.
- By simply pasting the text in the forum without it being inside a preformatted text box things can get awry and it's harder to get the help you're looking for (It's much easier to read the code too if it's preformatted).
- Lots of waits that don't necessarily need to be there. I would start to consider thinking with the logic of waiting for 'x' to appear rather than x amount of ms (That's wasted time!).
- Cmd+F - If your goal was to find a file, sure but then you'd be at the mercy of waiting for your computer to find the file. Given that you provided a filepath in your example, my guess is that you were referring to the "Go To Folder" Command (Shift+Cmd+G)
- Typing the path - this works but it is slower and will keep whatever you have in your clipboard. The solution I provided below is faster but won't keep your clipboard.
- Shift+DownAsterisk256 - I'm guessing you wanted to do this 256 times but you put the 'Asterisk(256)' within the quotation marks so technically you're saying something along the lines of whatever '*' means the "(256)" key. It's just not gonna work. I substituted this for a 'Cmd+A' so it selects everything within that directory.
Anywho, in general the forums are a great place to get help/support (and even ideas) but I've personally found that being specific and seeking knowledge rather than a solution will always get you better results. Anywho, ignoring what I just said, here's a solution that I believe should accomplish what you were trying to get done.
/// 0a. State the filepath to the folder containing your files. var searchText = '/Users/tiernan/Documents/IN PROGRESS SESSION/T112-G001-F001-K001-ARTIST-SONG' /// 0b. Set your computer's clipboard to the filepath specified above. sf.clipboard.setText({ text: searchText }) /// 1. Import Audio. sf.ui.proTools.menuClick({ menuPath: ["File","Import","Audio..."], }); /// 2. Wait for the "Import Audio" Dialog Box to appear. sf.ui.proTools.windows.whoseTitle.is("Open").first.children.whoseRole.is("AXStaticText").whoseValue.is("Import Audio").first.elementWaitFor(); /// 3. Go To Folder. sf.keyboard.press({ keys: "cmd+shift+g", }); /// 4. Wait 400ms. sf.wait({ intervalMs: 400, }); /// 5. Paste the filepath. sf.keyboard.press({ keys: "cmd+v", }); /// 6. Press Return (Enter). sf.keyboard.press({ keys: "return", }); /// 7. Wait 400ms. sf.wait({ intervalMs: 400, }); /// 8. Press the Right Key. sf.keyboard.press({ keys: "right", }); /// 9. Select all files in the specified directory. sf.keyboard.press({ keys: "cmd+a", }); /// #### From this point forward I'm only assuming what you're trying to do. /// 10. Click "Add All". sf.ui.proTools.windows.whoseTitle.is("Open").first.buttons.whoseTitle.is("Add All ->").first.elementClick(); /// 11. Wait 400ms. sf.wait({ intervalMs: 400, }); /// 12. Click "Open". sf.ui.proTools.windows.whoseTitle.is("Open").first.buttons.whoseTitle.is("Open").first.elementClick();
.
For future reference, if you're trying to learn more about soundflow these resources are invaluable:https://www.youtube.com/playlist?list=PLKWpZOwx5Z3jxnpNo_dQPhDQNRwp7DCNj
https://soundflow.org/docs/how-to/custom-commands/javascript-resources
https://www.youtube.com/playlist?list=PLyuRouwmQCjkYdv4VjuIbvcMZVWSdOm58
Best of luck sir! ;)
Nathan Salefski @nathansalefski
same exact timing lol
- TIn reply toTiernan_Cranny⬆:Tiernan Cranny @Tiernan_Cranny
Thank you all for your help. I am very new to this so please forgive me for being so green. i will try these out and hopefully learn from these new codes