Goto Directory from Open File Dialog Window
How can I create a script to navigate to a specific folder from within a dialog window such as the Open File dialog or the Export File dialog.
- Kitch Membery @Kitch2025-07-03 18:45:17.341Z
Hi @sbiss
Here is an example script for navigating and opening a session via ["File", "Open", "Session..."] in Pro Tools.
function openSession({ sessionPath }) { sf.ui.proTools.appActivateMainWindow(); sf.ui.proTools.menuClick({ menuPath: ["File", "Open", "Session..."] }); const openDialog = sf.ui.proTools.windows.whoseTitle.is("Open").first; openDialog.elementWaitFor(); //Open the path navigation sheet. sf.keyboard.press({ keys: "slash", }); const sheet = sf.ui.proTools.windows.whoseTitle.is("Open").first.sheets.first; sheet.elementWaitFor(); const pathField = sheet.textFields.first; pathField.elementSetTextFieldWithAreaValue({ value: sessionPath }); sf.keyboard.press({ keys: "return", }); sheet.elementWaitFor({ waitForNoElement: true }); openDialog.buttons.whoseTitle.is("Open").first.elementClick(); openDialog.elementWaitFor({ waitForNoElement: true }); } openSession({ sessionPath: "~/Desktop/Test Folder/Test Session Name.ptx" });
- SSteve Bissinger @sbiss2025-07-03 19:16:59.651Z
I may not have been clear in my question. I was actually looking for a generic script that I can use in any app's open file dialog once that dialog window is open.
- SSteve Bissinger @sbiss2025-07-03 19:20:47.327Z2025-07-03 19:40:40.090Z
It would also be awesome to know how to then move a file in the finder in the background.
The application is that I am converting some Finale files as they are dead ending the app. So I want to be able to navigate to the source folder for the finale files, open one, then when I export it I want to navigate to the folder where I am saving exported files and save it. It would then be even more awesome if I could move the finale file that's been exported into a folder for completed files.
I am sure there are also many other ways I might use this related to PT as well :)
Kitch Membery @Kitch2025-07-03 20:24:42.100Z
Hi again @sbiss
Can you please detail the manual steps that you'd take to perform this workflow?
I think I understand what you mean, but I feel like I'm making a lot of assumptions.
Thanks in advance.
- In reply tosbiss⬆:
Kitch Membery @Kitch2025-07-03 20:19:50.808Z
Hi Steve,
This is a script that will navigate to as specified directory of an "Open" or "Save" dialog in the frontmost app.
function navigateToDirectoryInOpenOrSaveDialog({ directoryPath }) { const dialog = sf.ui.frontmostApp.windows.find(w => { return w.title.value === "Open" || w.title.value === "Save" }); dialog.elementWaitFor(); dialog.elementRaise(); //Open the path navigation sheet. sf.keyboard.press({ keys: "slash", }); const sheet = dialog.sheets.first; sheet.elementWaitFor(); const pathField = sheet.textFields.first; pathField.elementSetTextFieldWithAreaValue({ value: directoryPath }); sf.keyboard.press({ keys: "return", }); } navigateToDirectoryInOpenOrSaveDialog({ directoryPath: "~/Desktop/Test Folder/" // Update with your target directory. });
- SSteve Bissinger @sbiss2025-07-03 20:47:23.395Z
This does exactly what I am looking for when I am in the open file dialog window. But it's not working when the "Save" or "Save As" windows are open.
- SSteve Bissinger @sbiss2025-07-03 20:57:35.392Z
Oh I see...the title of the window is slightly different when saving than what's in the script. Once I changed the window title it works as expected. This is great! Thank you Kitch!
Kitch Membery @Kitch2025-07-03 20:59:46.842Z
@sbiss...
Out of interest, what was the title of the window?- SSteve Bissinger @sbiss2025-07-03 21:22:14.641Z
I'm importing the finale files into MuseScore and when I hit save in MuseScore the window is titled "Save score". In Finale the window doesn't have a name, but your script seems to work anyway.
Kitch Membery @Kitch2025-07-03 21:30:24.903Z
Hi @sbiss
Nice... Here's an updated script that should work for all the Save/Open dialogs. :-)
function navigateToDirectoryInOpenOrSaveDialog({ directoryPath }) { const dialog = sf.ui.frontmostApp.windows.invalidate().find(w => w.title.value.startsWith("Open") || w.title.value.startsWith("Save") ); dialog.elementWaitFor(); dialog.elementRaise(); //Open the path navigation sheet. sf.keyboard.press({ keys: "slash", }); const sheet = dialog.sheets.first; sheet.elementWaitFor(); const pathField = sheet.textFields.first; pathField.elementSetTextFieldWithAreaValue({ value: directoryPath }); sf.keyboard.press({ keys: "return", }); } navigateToDirectoryInOpenOrSaveDialog({ directoryPath: "~/Desktop/Test Folder/" // Update with your target directory. });
- SSteve Bissinger @sbiss2025-07-03 22:24:44.938Z
Awesome! All seems to be working. This is going to be super helpful for many things :)
One last question...
What if I am in an app other than the Finder and I want to move a file in the Finder from one place to another? If I could add that to the arsenal then I would truly feel like a legend!
Kitch Membery @Kitch2025-07-03 22:59:22.105Z
Hi @sbiss
Moving files programatically can be destructive, so please proceed with caution. However, here is a thread where Christian provides a script for moving files.
- SSteve Bissinger @sbiss2025-07-04 19:44:43.351Z
Understood. I have less of a need to move files, but it's good to know how. I will have to experiment with this later. Thank you @Kitch !!!
Kitch Membery @Kitch2025-07-04 20:04:06.416Z
You're welcome @sbiss :-)