In a thread on this forum there is an interesting solution on how to open a duplicate of an already open Finder window with the help of an AppleScript: How do you duplicate current open Finder view?

With the new tabbed Finder in OS X 10.9 Mavericks, I am wondering if there is a way to implement an AppleScript that opens the duplicate in a new Finder tab instead of a new Finder window? Did anybody succeed in finding a solution?

You can do it by pressing:

cmd+ctrl+O

on any folder and it'll show up in a new tab.

Finder's dictionary doesn't have support for tabs, but you can simulate pressing command-T:

tell application "Finder"
    activate
    set t to target of Finder window 1
    set toolbar visible of window 1 to true
end tell
tell application "System Events"
    keystroke "t" using command down
end tell
tell application "Finder"
    set target of Finder window 1 to t
end tell

The target of a Finder window is the folder shown on the title bar, which does not depend on what items are selected in list view.

  • Works exactly as I wanted! Thank you. I compiled the script as an app and put its icon on the Finder toolbar, so I always have it handy on every Finder window. – magoo Oct 31 '13 at 10:15
  • @magoo: you could create a service with automator that runs this apple script and then assign a keyboard shortcut through SystemPreferences->Keyboard->Shortcuts->AppShortcuts. – DudeOnRock Dec 16 '13 at 1:42
  • Before using keystroke, it's better to do set frontmost to true first, make sure that keystroke is execute on Finder not something else. – Albert Jun 15 '15 at 6:30

I wrote a script for this today, pretty similar to how @Lri has done it.

https://gist.github.com/n8henrie/0ceef75964bd153f910d

-- duplicateFinderTab.scpt
-- Uses a hacky workaroud to duplicate the frontmost Finder tab,
-- since Apple hasn't provided great AppleScript support for this.

on new_tab()
    tell application "System Events" to tell application process "Finder"
        set frontmost to true
        tell front menu bar to tell menu "File" to tell menu item "New Tab"
            perform action "AXPress"
        end tell
    end tell
end new_tab

on run {}
    tell application "Finder"
        if (count of Finder windows) > 0 then set duplicate_me to target of front Finder window
    end tell

    -- Short delay may or may not be necessary, mine seems to work without.
    -- delay 0.2

    new_tab()
    tell application "Finder"
        set target of front Finder window to duplicate_me
    end tell
end run

This is @n8henrie's solution, except with a tweak to reselect the selected items, which I kind of like:

-- duplicateFinderTab.scpt
-- Uses a hacky workaroud to duplicate the frontmost Finder tab,
-- since Apple hasn't provided great AppleScript support for this.

----------------------------------------------
on run {}
    tell application "Finder"
        if (count of Finder windows) > 0 then set duplicate_me to target of front Finder window
        set _sel to the selection
    end tell

    -- Short delay may or may not be necessary, mine seems to work without.
    -- delay 0.2

    new_tab()

    tell application "Finder"
        set target of front Finder window to duplicate_me
        select _sel
    end tell
end run

----------------------------------------------
on new_tab()
    tell application "System Events" to tell application process "Finder"
        set frontmost to true
        tell front menu bar to tell menu "File" to tell menu item "New Tab"
            perform action "AXPress"
        end tell
    end tell
end new_tab

Click the finder tab you want to duplicate, then CMD+T.

  • This is just wrong. Delete this. – Mike Kormendy Apr 7 '17 at 3:56

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.