我一直在浏览the documentation for iTerm2's Python API,试图找出一种获取和设置
名称/标题的方法我也尝试了iTerm Python REPL,但无济于事。
窗口标题似乎仍然可以使用旧的外壳转义码设置,例如使用这样的功能:
window_title() {
echo -ne "\e]2;$@\a\e]1;$@\a"
}
但是我什至找不到其他设置会话标题或标签标题的方法,更不用说通过Python API了。
如果您查看其窗口效果,窗口标题,选项卡标题和会话标题之间的关系,则可以更清楚地看到它们之间的关系(假设会话标题设置为显示会话名称,如果未设置会话名称,则可能会造成混淆。保持一致)。
答案 0 :(得分:1)
阅读:
# https://iterm2.com/python-api/session.html#iterm2.Session.async_get_variable
session_title = (await session.async_get_variable("autoName"))
设置:
# https://iterm2.com/python-api/session.html#iterm2.Session.async_set_name
await session.async_set_name(session_title + "!")
这是一个更详细的示例:
async def get_all_sessions(app:iterm2.app.App):
for window in app.windows:
window_title = (await window.async_get_variable("titleOverride"))
print("window title: %s" % (window_title))
# add window title suffix
# await window.async_set_title(window_title+" ;)")
# remove the added window title suffix
# await window.async_set_title(window_title[0:-3])
# print("window detailed: %s" % (window.pretty_str()))
for tab in window.tabs:
tab_title = (await tab.async_get_variable("titleOverride"))
print("\t\ttab title: %s" % (tab_title))
for session in tab.sessions:
# https://iterm2.com/documentation-session-title.html
# https://stackoverflow.com/questions/56069701/how-do-i-get-and-set-the-titles-of-the-window-tab-and-session-in-iterm-2-with
# https://iterm2.com/python-api/session.html#iterm2.Session.async_get_variable
session_title = (await session.async_get_variable("autoName"))
print("\t\t\tsession title: %s" % (session_title))
if session_title == "colabo-GIST":
print("\t\t\t: changing session name: %s" % (session_title))
# https://iterm2.com/python-api/session.html#iterm2.Session.async_set_name
await session.async_set_name(session_title + "!")
# await session.async_inject(code)