Getting the full path of file selected on Chrome open file dialogue

On Chrome, I am on the open file dialogue. I want to obtain the full path of the file I'm selecting from the window before I click the "open" button on the dialogue.

I have tried several tokens like %FinderSelection% but that takes the file from a Finder window, not on this open dialogue from Chrome. I've tried several AppleScript to no avail :pensive:

Any ideas on how I can achieve this? Thanks! :pray:

Here's a bad idea, which I'm sure others will improve upon: You can right-click in that dialog and select Show in Finder. Assuming you're using your mouse to click on the item you want, just run the macro to send a right-click at the current mouse location, then select "Show in Finder" by typing letters or with the arrow keys (in KM Send Keystroke actions).

Have the macro wait for Finder to be Frontmost, then copy the %FinderSelection% token to a variable, then reactivate Chrome.

Ugly as heck, but it should work.

-rob.

Hello @David_Chavez :wave:

Open and Save Dialogs using the Files as references…. This is due to the design of the API they are build on top of, to make it easy for developers to integrate them in their Applications…

When called from Outside of the Finder they have to act like if they were called in the Finder application.

So what you’re trying to accomplish is not possible. I’m sorry.

You can either pick a File and get its reference as alias to a variable and build up on that by scripting the dialog or by using it to open or save a file like they are supposed to work when integrated into Applications.

But not both at the same time.

Greetings from Germany :de:

Tobias

Here's a basic functional macro:

Download Macro(s): Get Path in Open Dialog.kmmacros (28 KB)

Macro screenshot

Macro notes
  • Macros are always disabled when imported into the Keyboard Maestro Editor.
    • The user must ensure the macro is enabled.
    • The user must also ensure the macro's parent macro-group is enabled.
System information
  • macOS 14.7
  • Keyboard Maestro v11.0.3

You'll see it's probably not ideal, because it depends on mouse location to make the click—there's no way to "see" whatever it is that you may have selected in the Open dialog with KM that I can find. You could possibly do it with a found image, looking for the shape/color of part of a selection box if you use column view, but that wouldn't work for the other view modes.

But if you do put your mouse over the selected item and press Control-P, the path to that item will appear onscreen (and is saved to a variable).

-rob.

Thanks @griffman. I've been playing with different options and have now a working macro similar to yours. Very ugly, but functional.

Instead of using mouse location, I use control + return, I can invoke the right-click context menu on the selected file, and then do a "show in finder", copy the full path, go back to Chrome, and then do what I want on the file.

So yeah, ugly as heck, but working and saving me some clicks and a few seconds on each repetition, which means lots of minutes for lots of files :blush:

Thanks!

I always say Keyboard Maestro can solve any problem, but sometimes ugly solutions are necessary. And generally speaking, that's because of apps or macOS, not because of KM itself.

1 Like

I forgot that Sequoia allows Control-Return—that's perfect. And I think that's probably about as good as you'll get for trying to work with the Open dialog.

-rob.

1 Like

Actually, it can be slightly improved:

Add a Hide A Specific Application: Finder action just after the Pause until Finder is at the front action, and you'll barely see the Finder flash.

Then at the end, after reactivating Chrome, add a Show A Specific Application: Finder to make it visible again (but Chrome will remain frontmost). You could also use a Close Window action in there somewhere to close the Finder window that opened, if you want.

But with the Hide action added, the flash is much less jarring, as you see the window only for a split second.

-rob.

1 Like

Why do you want to do this? What's the workflow?

There may be better ways -- for example, using KM's "Prompt for File" action to get the path then telling Chrome to open that path, or have a macro that opens Chrome's "Open..." dialog box normally and then grabs the file path from the address bar once the file's been opened.

Thanks @griffman. I'll try that improvement :wink:

@Nige_S It's not that I'm opening the file on a new window in Chrome. It's that I'm uploading that file to a page, and when selecting the file, I want to do something with that file on my computer after I'm uploading that file. Specifically, this is my workflow: I upload subtitles to videos, and then I select that file from my computer (this is where the open dialogue starts from Chrome). The file is in a folder where I have all the srt files. Just after uploading, I want to move that srt to another folder, indicating that I've already uploaded that file. The objective is that I only have srt files pending to upload in that original directory.

Maybe I didn't give the full details, but thought it was not needed. So, that's why I'm starting with that open dialogue from the system, which is where I want the magic to happen :wink: Thanks for sharing your thoughts :blush:

If I understand this correctly, then @Nige_S is correct, and you could just reverse the process. Start in Finder, and select the file to upload. Launch the macro, and for the first step, get the selected item's path into a variable.

Have the macro switch to Chrome, press Command-O then Shift-Command-G to open the Go To input box, and insert text by pasting with the variable containing the path. That should upload the file.

Then have the macro move the file out of the folder to its new home.

Did I understand the process correctly?

-rob.

As with @griffman, I'd still go the other route -- run a macro that uses either the current Finder selection or a KM "Prompt for File" action to get the path, triggers the web page's "upload" dialog, pastes the path in and OKs everything. You should be able to find something on the page -- a progress, a "Completed" icon, or similar -- that you can use "Pause Until..." on and, when the upload is complete, move the srt file.

Pressing Command-O will not work, as I want to upload a file, not open the file itself on Chrome.

Maybe it's too specific, but here's what I do:

  1. Start YouTube Studio, and click on the "upload file"
    Xnapper-2024-11-07-09.47.47-6F4034B7-AA30-4DFC-A793-77D62E0335F4
  2. This triggers the open dialogue.
  3. I have a macro that takes from the browser (via a CSS selector) the name of the video and with that name of the video, looks on my computer for an srt that has the same name. This is useful as it gets the correct srt from my computer for the video I am working on.
  4. Then, when the file is selected on the open dialogue, my new macro (this macro we are discussing), gets the full path of that file (opening finder, taking the selected file through the token %FinderSelection%, and storing it on a variable) and then confirms on the open dialogue.
  5. After the file is opened and YouTube has the srt file, the same macro waits 2 seconds, and then moves the file to a completed srt directory.

Steps 4 and 5 are the steps I'm doing on this new macro. So, as far as I understand, Command-O will not work, as my workflow starts from my browser window in YouTube studio and cannot start from my Finder window :blush:

Doesn't that return the path to the file? So you could pause the macro at that point while you manually open the upload dialog, then un-pause and macro the ⇧⌘G, insert the path by pasting, "Type a Keystroke: Return", then move on to the rest of what you want to do. Or use browser-based actions or "Click at Found Image" open the upload dialog for you.

Lots of Forum examples on how to drive the standard OS "Open" dialog, complete with pauses until buttons become available etc.

Thanks for your interest @Nige_S

Unfortunately, at that step, I don't have the full path for the file. I use ⇧⌘G and then paste the name of the video and then add a srt to search for the file, as it's not an entire match. So, that's more like a manual process.

So, if the name of the video is the same as the srt, that would help, but given the circumstances of what I have and the workflow, this is the limitation :pensive: But even if the second macro is ugly, it works wonders and is saving me lots of time already :sunglasses:

Ah, so not a "proper" search, but a search within the (another!) "Open" dialog.

What you've got now appears to be working for you, and that's great.

But consider that

If there are no subfolders then your file path is always going to be

/path/to/srt/folder/name-of-video.srt

...so you don't need to manually interact with either of those dialogs -- you know the path, just ⇧⌘G in the dialog and enter it.

Even if there are sub-folders there will be (I hope) some logic to the structure that you could use. Failing that you could use mdfind to get the path and use that in the dialogs.

So plenty of opportunities to reduce your grunt-work, should you wish to.

Oh, thanks @Nige_S That is really helpful.

I modified the macro to do it all in one shot without opening the finder. Now, I take the partial string I have from Chrome (not exactly the same as the srt file), and use find command on a shell command, and then pass the result to a variable and to all that needs to be done. Thanks! :pray:

1 Like