iTerm2获取当前会话档案?

时间:2013-05-27 07:59:24

标签: applescript iterm iterm2

所以我知道有一种方法可以通过echo -e“\ 033]设置会话配置文件50; SetProfile = Foo \ a”但是有没有办法获取当前会话的配置文件?

3 个答案:

答案 0 :(得分:4)

您可以通过查看$ITERM_PROFILE变量来获取会话(对于那些正在查看的人)。它可以帮助查看printenv的打印输出以查看此类内容。

答案 1 :(得分:2)

我没有找到任何方法来获取配置文件的名称,除此之外:

tell application "System Events" to tell process "iTerm"
    keystroke "i" using command down
    set p to value of text field 1 of tab group 1 of group 1 of window 1
    click button 1 of window 1
end tell
p

您可以通过某些属性识别配置文件:

tell application "iTerm" to tell current session of terminal 1
    background color is {0, 0, 0} and transparency is 0.0
end tell

字典中记录的属性:

背景颜色,背景图片路径,粗体颜色,内容,光标颜色,cursor_text颜色,前景色,id,名称,编号,所选文本颜色,选择颜色,透明度,tty

答案 2 :(得分:2)

这是我提出的最简单的Applescript:

tell application "iTerm-2"
    get profile name of current session of current window
end tell

这是一个简单的bash脚本,它使用它来设置配置文件,运行命令,然后再次设置配置文件。它使用第一个参数作为配置文件,其余作为命令(例如 script< profile>< command> )。

#/bin/bash

#get the current window settings
CUR_SETTINGS=`osascript -e 'tell application "iTerm-2"
get profile name of current session of current window
end tell'`

#Restore the current settings if the user ctrl-c's out of the command
trap ctrl_c INT
function ctrl_c() {
        echo -e "\033]50;SetProfile=$CUR_SETTINGS\a"
        exit
}

#set profile
echo -e "\033]50;SetProfile=$1\a"
shift

#run command
$@

#Restore settings
echo -e "\033]50;SetProfile=$CUR_SETTINGS\a"
相关问题