使用新配置文件

时间:2015-11-19 13:37:03

标签: macos command-line

我在Mac上使用OSX Yosemite和内置终端。我有很多终端窗口在大部分时间都在运行,并且很难在所有这些窗口中导航,因为它们看起来都很相似。所以我想要做的就是像往常一样运行我的命令,但是在一个带有所选配置文件的新终端窗口中。

通常在vim中打开my_script我会输入命令行

$ vim my_script

但我希望能够写出这样的内容:

$ vim my_script(和以前一样)然后有一些命令说“在一个带有profile = Homebrew的新终端窗口中打开它”

有人知道这是否可行?非常感谢你。

1 个答案:

答案 0 :(得分:0)

输入AppleScript。

它没有实现完全你描述的内容,但我认为它足够接近。你是否使用它取决于你。

您可以使用此命令

osascript -e 'tell app "system events" to tell process "Terminal" to tell menu bar 1 to tell menu bar item "Shell" to tell menu "Shell" to tell menu item "New Window" to tell menu "New Window" to click menu item "Basic"'

或,以扩展形式

tell app "system events" 
    tell process "Terminal" 
        tell menu bar 1 
            tell menu bar item "Shell" 
                tell menu "Shell" 
                    tell menu item "New Window" 
                        tell menu "New Window" 
                            click menu item "Basic" #or any other profile
                        end tell
                    end tell
                end tell
            end tell
        end tell
    end tell
end tell

使用所需的配置文件创建新的终端窗口。 (在本例中我使用了Basic)

如果收到错误

System Events got an error: osascript is not allowed assistive access

然后看this SO answer by @NGAFD如何解决这个问题。

转到系统偏好设置>安全和隐私>隐私>可访问性并确保终端在列表中并进行检查。

相关问题