从命令行打开新的终端选项卡 (Mac OS X) [英] Open new Terminal Tab from command line (Mac OS X)

查看:42
本文介绍了从命令行打开新的终端选项卡 (Mac OS X)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Mac OS X 的终端中从当前打开的选项卡中的命令行打开一个新选项卡?

Is it possible to open a new tab in Mac OS X's terminal from the command line in a currently opened tab?

我知道在终端中打开新选项卡的键盘快捷键是CMD+t",但我正在寻找在命令行中执行的基于脚本的解决方案.

I know that the keyboard shortcut to open a new tab in Terminal is "CMD+t" but I am looking for a script-based solution executed in the command line.

推荐答案

试试这个:

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 变量,并将最后一行替换为:


But if you need to run dynamic command, set myCommand variable, and replace last line with:

-e "tell application "Terminal" to do script "${myCommand};" in selected tab of the front window";

这篇关于从命令行打开新的终端选项卡 (Mac OS X)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆