我想创建一个苹果脚本,它只启动一次iTerm2配置文件。如果此配置文件的会话已在运行,则应将相应的窗口聚焦,否则应启动新的会话。
到目前为止,我对植入的想法是
启动一个新会话。
但是,我还没有设法在窗口上循环,并根据预定义的字符串检查它们的名称。
发布于 2022-01-18 21:53:58
经过多次试验,我终于想出了答案。下面的脚本使用概要文件的名称作为参数,并执行我在问题中描述的内容。
on run argv
set isopen to false
set targetName to (item 1 of argv)
tell application "iTerm2"
repeat with w in windows
set wn to name of w
if wn = targetName then
set isopen to true
tell application "System Events"
perform action "AXRaise" of window (index of w) of process "iTerm2"
end tell
activate
exit repeat
end if
end repeat
if not isopen then
create window with profile targetName
end if
end tell
end runhttps://stackoverflow.com/questions/70761795
复制相似问题