“Go to Current Finder Selection” - Macro + JXA help request

Hi guys, below is a macro I use many times a day to jump the current open/save/export window to the current Finder selection.

This saves me a lot of time. I find it’s much faster to have a window open in the Finder (and be operating from within it) than to try to wrangle those open/save/export windows, since they don’t remember view settings.

If anyone knows a little JXA, I am interested in changing the ⇧⌘G portion, along with all the UI manipulation that follows, into a simple JXA command. That would speed this up considerably!

Go to Current Finder Selection.kmmacros (5.4 KB)

I wonder if you can skip the ⇧⌘G ?

I have a feeling that as soon as we start to type the first / of a path in one of those dialogs, the Go To field pops up anyway, so you might be able to just use some variant on this theme:

Which gets the Finder folder path with:

function run() {
    return decodeURI(
        '/' + Application('Finder')
        .insertionLocation()
        .url()
        .slice(8)
    );
}

But perhaps the typing is a bit slow ?

4 Likes

Hey Jack,

As far as I know there's no way to change the location of an Open/Save dialog without using the UI.

Unless you have Default Folder of course.

Default Folder actually has a keyboard shortcut for going to the frontmost window in the Finder.

It is also scriptable.

-Chris

2 Likes

Thanks! Yes, you are correct, the / works, but the typing is a bit slow. Your Javascript does speed it up noticeably, though.

I will look into Default Folder! Thanks for the tip.