Opening a new Finder *tab* from command line
I'm wondering if there is a means of opening a new finder tab (not window) from the command line. I can do, e.g.,
open .
but this opens a new window. It would be nice to open a new tab in the most-recently active existing finder window.
You really can't via any “normal” shell commands, but you can run AppleScript via the shell to accomplish the task.
Here's a Bash function with the command fnt
for “Finder New Tab”:
function fnt()
{
osascript -e 'tell application "System Events" to perform action "AXPress" of menu item "New Tab" of menu "File" of menu bar item "File" of menu bar 1 of application process "Finder"'
}
Add the above bash function
to your ~/.bash_profile
or ̃/.profile
file to use it. After adding, restart Terminal or use the source
command in the current Terminal window to have access to the fnt
function.
This should work on any version macOS that has the “New Tab” command in the “File” menu. You'll also need to add Terminal to: System Preferences > Security & Privacy > Privacy Accessibility
I understand some improvement to AppleScript has been made in Mojave relative to tabs in the Finder, but I'm still using macOS Sierra 10.12.6 and can't test.