我正在尝试创建一个脚本来打开iTerm2
窗口,将其垂直分成 3 个窗格,并在每个窗格中运行一些命令。
到目前为止,这是我的尝试:
tell application "iTerm2"
activate
-- Create main window
create window with default profile
tell current session of current window
set name to "frontend"
write text "cd ~/Documents/frontendDir"
split vertically with default profile
end tell
tell second session of current window -- ERROR HERE
set name to "backend"
write text "cd ~/Documents/backendDir"
split vertically with default profile
end tell
tell third session of current window
set name to "apollo-server"
write text "cd ~/Documents/GitHub/apolloDir"
end tell
end tell
第一部分关于创建frontend
似乎可以正常工作,因为窗口已正确打开并且命令cd ~/Documents/frontendDir
在其中正确执行。该窗口也被垂直分割一次,因为我很确定当我尝试访问窗口的第二个窗格时它会停止执行。
我收到此错误:iTerm got an error: Can’t get session 2 of current window
提前致谢
iTerm session
对象包含在tabs
, not windows
。因此,正如您在下面的脚本片段中看到的,我通过以下方式引用了要写入的每个会话current tab
of the current window
:
tell application "iTerm"
activate
set W to current window
if W = missing value then set W to create window with default profile
tell W's current session
split vertically with default profile
split vertically with default profile
end tell
set T to W's current tab
write T's session 1 text "cd ~/Desktop"
write T's session 2 text "cd ~/Downloads"
write T's session 3 text "cd ~/Documents"
end tell
据我所知,你不能设置name
的财产session
;它被设置为会话框架的标题。每个都可以参考一下session
通过它的索引(正如我在这里所做的那样);它是id
财产;或其tty
财产;所有这些都是独特的价值。
正如您所看到的,索引似乎是按会话的创建排序的:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)