加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – iTerm2中的新标签

发布时间:2020-12-15 21:55:21 所属栏目:安全 来源:网络整理
导读:我正在使用Iterm2版本Build 3.0.4 我想创建别名以从命令行打开新选项卡(在bash中) 我试过这段代码: function tab () { osascript /dev/null EOFactivate application "iTerm" tell application "System Events" to keystroke "t" using command down tell a
我正在使用Iterm2版本Build 3.0.4
我想创建别名以从命令行打开新选项卡(在bash中)
我试过这段代码:

function tab () {
    osascript &>/dev/null <<EOF
activate application "iTerm"
    tell application "System Events" to keystroke "t" using command down
    tell application "iTerm" to tell session -1 of current terminal to write text "pwd"
EOF
}

但它不起作用.任何人都可以使用此版本(或更新版本)解决问题吗?

解决方法

iTerm2 v3具有大大改进的AppleScript支持,因此您现在可以直接创建标签,而无需发送按键:

tab() {
    osascript &>/dev/null <<EOF
      tell application "iTerm"
        activate
        tell current window to set tb to create tab with default profile
        tell current session of current window to write text "pwd"  
      end tell
EOF
}

要水平拆分新选项卡(如按??D所示),请添加:

tell current session of current window to split horizontally with same profile

要将pwd写入拆分创建的新会话(新选项卡的下半部分):

tab() {
    osascript &>/dev/null <<EOF
      tell application "iTerm"
        activate
        tell current window to set tb to create tab with default profile
        tell current session of current window to set newSplit to split horizontally with same profile
        tell newSplit
          select
          write text "pwd"
        end tell    
      end tell
EOF
}

要浏览iTerm2的可用AppleScript命令,请打开Script Editor.app,选择File>打开字典…,然后是iTerm.app.

还要考虑我的ttab CLI,它包括选项卡/窗口创建以及Terminal.app和iTerm2.app的高级功能(但它不支持拆分选项卡).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读