13

I have the setting "open folders in new tabs" (instead of new windows) in finder turned on but this does not seem to influence what my other apps do when they open a folder. Launchbar and a shell script I run from emacs still opens folders in small finder windows. How can I make folders opened from external apps all appear in one tabbed finder window?

Edit: Bmike in the comment is right that this could probably be done via an applescript. Something like this:

  1. You have some script that gives you the path of the folder you want to open.
  2. You pass this as a variable to an applescript.
  3. This applescript saves the pathname as a variable
  4. It activates finder or opens a particular folder with finder.
  5. It sends the keystroke command + t to open a new tab (or does the same with a command to finder).
  6. It sends the keystroke command + shift + g to finder opening the go to folder with path x menu/window.
  7. It writes (systemevents) or pastes it (set clipboard to the variable that is the path of the folder) into this menu/window.
  8. Click enter. The folder is opened.
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"

1

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

You must log in to answer this question.