Is it possible to open a new tab in Mac OS X\'s terminal from the command line in a currently opened tab?
I know that the keyboard shortcut to open a new tab in Term
The keyboard shortcut cmd-t
opens a new tab, so you can pass this keystroke to OSA command as follows:
osascript -e 'tell application "System Events"' -e 'keystroke "t" using command down' -e 'end tell'
If you are using iTerm this command will open a new tab:
osascript -e 'tell application "iTerm" to activate' -e 'tell application "System Events" to tell process "iTerm" to keystroke "t" using command down'
when you are in a terminal window, command + n => opens a new terminal and command + t => opens a new tab in current terminal window
What about this simple snippet, based on a standard script command (echo):
# set mac osx's terminal title to "My Title"
echo -n -e "\033]0;My Title\007"
Here's how it's done by bash_it:
function tab() {
osascript 2>/dev/null <<EOF
tell application "System Events"
tell process "Terminal" to keystroke "t" using command down
end
tell application "Terminal"
activate
do script with command "cd \"$PWD\"; $*" in window 1
end tell
EOF
}
After adding this to your .bash_profile, you'd use the tab
command to open the current working directory in a new tab.
See: https://github.com/revans/bash-it/blob/master/plugins/available/osx.plugin.bash#L3
osascript -e 'tell app "Terminal"
do script "echo hello"
end tell'
This opens a new terminal and executes the command "echo hello" inside it.