2013-05-27 31 views

回答

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

+0

Yah不幸的是沒有綁定的術語:( – gdoubleod

2

這是最簡單的AppleScript我都拿出來做到這一點:

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

,這裏是使用這種情景模式設置爲一個簡單的bash腳本,運行命令,然後再次設置配置文件。它使用第一個參數作爲配置文件,其餘爲命令(例如腳本<配置文件> <命令>)。

#/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 
[email protected] 

#Restore settings 
echo -e "\033]50;SetProfile=$CUR_SETTINGS\a" 
+0

非常感謝,這正是我所期待的。 –

1

您可以通過檢查$ITERM_PROFILE變量(對於那些現在希望)獲取會話。查看printenv的打印輸出可以幫助您查看類似的事情。

+0

真棒看起來像他們在第3版中加入了這個! – gdoubleod