在Mac OS X的终端中,是否可以在当前打开的选项卡中通过命令行打开新的选项卡?
我知道在终端中打开新选项卡的键盘快捷键是"CMD+t“,但我正在寻找在命令行中执行的基于脚本的解决方案。
发布于 2011-08-24 23:15:24
试试这个:
osascript -e 'tell application "Terminal" to activate' \
-e 'tell application "System Events" to tell process "Terminal" to keystroke "t" using command down' \
-e 'tell application "Terminal" to do script "echo hello" in selected tab of the front window'
但如果您需要运行动态命令,请设置myCommand
变量,并将最后一行替换为:
-e "tell application \"Terminal\" to do script \"${myCommand};\" in selected tab of the front window";
发布于 2011-08-24 15:15:56
osascript -e 'tell app "Terminal"
do script "echo hello"
end tell'
这将打开一个新终端,并在其中执行命令"echo hello“。
发布于 2011-11-19 03:41:06
下面是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
}
将此文件添加到.bash_profile后,您可以使用tab
命令在新选项卡中打开当前工作目录。
请参阅:https://github.com/revans/bash-it/blob/master/plugins/available/osx.plugin.bash#L3
https://stackoverflow.com/questions/7171725
复制相似问题