Make folders opened by external apps open in a new finder tab rather than a window

Solution 1:

I did this, not sure if it will answer it for you.

Finder Preferences > General > check "open folders in tabs instead of new windows"

Solution 2:

Thanks for the idea. I got the applescript finished.

Put the following in your ~/.bashrc or ~/.zshrc

# open the current folder in Finder's tab
function oft() {
    # if no arguments are given, we use the current folder
    oft_absolute_path=$(cd ${1:-.}; pwd)

    # execute the applescirpt
    osascript 2>/dev/null <<EOF

        # Finder returns a path with trailing slash
        # But PWD doesn't have one, so we add one for it
        set new_tab_path to "$oft_absolute_path" & "/"

        tell application "Finder"
            activate

            if not (exists window 1) then
                make new Finder window
            end if

            try
                set finder_path to POSIX path of (target of window 1 as alias)
            on error
                # the finder's window doesn't contain any folders
                set target of front window to (new_tab_path as POSIX file)
                return
            end try
        end tell

        if new_tab_path = finder_path then
            # the finder's tab is already there
            return
        end if

        # open new tab in Finder
        tell application "System Events" to keystroke "t" using command down

        # set the Finder's path
        tell application "Finder"
            set target of front window to (new_tab_path as POSIX file)
        end tell

        return
    EOF
    # clear the tempory veriable
    unset oft_absolute_path
}

In terminal, type

oft .

to open the current folder in Finder's new tab.

The bash script is used for retrieving the absolute path, which I found difficult to do in appplescript.

UPDATE

I have made a more extensive (and complicated) version which will open the same tab for the same folder. Get it here