确定iTerm2中的window name/number
Determine the window name/number in iTerm2
我在 MacOS (Sierra) 上使用 iTerm2。我有多个 iterm2 运行ning 实例,每个实例都有一个以数字为前缀的标题,该数字随着每个 运行ning window.
递增
我想在命令行上运行一个shell命令到return这个号码,有人知道如何得到这个信息吗?
我正在寻找类似的东西:
$ iterm_get_number()
2
我能够使用 applescript 获取名称,以下脚本转储了打开的 iTerm windows 的列表。因为我有兴趣在 python 脚本中使用这些名称,所以我也包含了一个小片段来执行此操作。
get_window_names.applescript
on run
set returnNames to {}
tell application "iTerm"
repeat with theWindow in windows
tell theWindow
set end of returnNames to get name
end tell
end repeat
end tell
return returnNames
end run
python 用于从上面的脚本中提取信息
out = subprocess.check_output(['osascript', 'get_window_names.applescript'])
print [x.strip() for x in out.split(',')]
我在 MacOS (Sierra) 上使用 iTerm2。我有多个 iterm2 运行ning 实例,每个实例都有一个以数字为前缀的标题,该数字随着每个 运行ning window.
递增我想在命令行上运行一个shell命令到return这个号码,有人知道如何得到这个信息吗?
我正在寻找类似的东西:
$ iterm_get_number()
2
我能够使用 applescript 获取名称,以下脚本转储了打开的 iTerm windows 的列表。因为我有兴趣在 python 脚本中使用这些名称,所以我也包含了一个小片段来执行此操作。
get_window_names.applescript
on run
set returnNames to {}
tell application "iTerm"
repeat with theWindow in windows
tell theWindow
set end of returnNames to get name
end tell
end repeat
end tell
return returnNames
end run
python 用于从上面的脚本中提取信息
out = subprocess.check_output(['osascript', 'get_window_names.applescript'])
print [x.strip() for x in out.split(',')]