문제

So I know there is a way to set the session profile via echo -e "\033]50;SetProfile=Foo\a" but is there a way to get the current session's profile?

도움이 되었습니까?

해결책 2

I didn't find any way to get the name of the profile apart from something like this:

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

You might be able to identify profiles by some properties:

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

Properties documented in the dictionary:

background color, background image path, bold color, contents, cursor color, cursor_text color, foreground color, id, name, number, selected text color, selection color, transparency, tty

다른 팁

You can get the session by checking the $ITERM_PROFILE variable (For those looking now). It can help to look at the printout from printenv to see things like this.

This is the simplest Applescript I have come up with to do this:

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

And here's a simple bash script which uses this to set a profile, run a command, then set the profile back again. It uses the first argument as the profile, and the rest as the command (e.g. 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"
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top