0

我只是在学习编写脚本,我想要一个在单个窗口中打开 13 个选项卡的解决方案,为每个窗口运行此命令,每个选项卡的值递增“telnet localhost 2001”...“telnet localhost 2013”​​,然后命名每个选项卡R1..R1,然后 SW1..SW4,然后 BB1..BB3。

这就是我可以对第一部分和第三部分但不是第二部分的方法。

tell application "Terminal"  
activate  
tell application "System Events" to keystroke "n" using {command down}  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 1 of window 1 to "R1"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 2 of window 1 to "R2"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 3 of window 1 to "R3"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 4 of window 1 to "R4"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 5 of window 1 to "R5"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 6 of window 1 to "R6"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 7 of window 1 to "SW1"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 8 of window 1 to "SW2"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 9 of window 1 to "SW3"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 10 of window 1 to "SW4"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 11 of window 1 to "BB1"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 12 of window 1 to "BB2"  
tell application "System Events" to keystroke "t" using {command down}  
set custom title of tab 13 of window 1 to "BB3"  

end tell

它需要为这些值运行一个子程序,但是在我让它按我想要的方式工作之后我可以处理它。

任何人都可以帮我解决我的问题,因为添加

do script ("telnet localhost 2001")

目前在每个选项卡下打开失败?

4

3 回答 3

0

这是我当前的,糟糕的代码,但可以完成工作。注意我需要先打开终端,否则会出现上述错误,创建一个额外的“BB2”选项卡,没有运行 telnet 脚本,并且在某些选项卡中输入了第二个脚本行,而有些则没有。

如果有人可以提供帮助,我将不胜感激。

干杯。

告诉应用程序“终端”——应用程序
激活
告诉应用程序“系统事件”使用 {command down} 击键“n”使用 {command down}
告诉应用程序“系统事件”击键“t”
执行脚本“telnet localhost 2001”前窗口标签 1
执行脚本“” 在前窗口标签 1 中
执行脚本“” 在前窗口标签 1 中
执行脚本 “sh ip int bri” 在前窗口标签 1 中
延迟 0.1
设置窗口 1 的标签 1 的自定义标题到“R1”
告诉应用程序“系统事件”使用{command down}击键“t”
执行脚本“telnet localhost 2002”在前窗口的选项卡 2 中
执行脚本“”在前窗口的选项卡 2 中
在前面窗口的选项卡 2 中执行脚本“” 在前面窗口的选项卡 2 中
执行脚本“sh ip int bri” 在前面窗口的选项卡 2 中
执行脚本“”
延迟 0.1
将窗口 1 的选项卡 2 的自定义标题设置为“R2”
告诉应用程序“系统事件”使用 {command down} 击键“t”
在前窗口的选项卡 3 中执行脚本“telnet localhost 2003”在前窗口的选项卡 3 中
执行脚本“”在前窗口的选项卡 3 中
执行脚本“”在前窗口的选项卡 3 中
执行脚本“sh ip int bri” 在前窗口选项卡 3 中
执行脚本“” 在前窗口选项卡 3 中
延迟 0.1
将窗口 1 选项卡 3 的自定义标题设置为“R3”
使用 {command down} 告诉应用程序“系统事件”击键“t”
在前窗口的选项卡 4 中执行脚本“telnet localhost 2004” 在前窗口的选项卡 4 中
执行脚本“”在前窗口的选项卡 4 中
执行脚本“”在前窗口的选项卡 4 中
执行脚本“sh ip int bri”在前窗口的选项卡 4 中
执行脚本“ " 在前面窗口的选项卡 4 中
延迟 0.1
将窗口 1 的选项卡 4 的自定义标题设置为 "R4"
使用 {command down} 告诉应用程序 "系统事件" 击键 "t"
在前面的选项卡 5 中执行脚本 "telnet localhost 2005"窗口
执行脚本“”在前窗口的选项卡 5 中
执行脚本“”在前窗口的选项卡 5 中执行脚本“sh ip int bri”在前窗口的选项卡 5 中执行脚本“”在前窗口延迟 0.1 的选项卡 5 中,将窗口 1 的选项卡 5 的自定义标题设置为“R5”
使用 {command down} 告诉应用程序“系统事件”击键“t”
在前面窗口的选项卡 6 中执行脚本“telnet localhost 2006” 在前面窗口的选项卡 6 中
执行脚本“”在前面窗口的选项卡 6 中
执行脚本“”在前面窗口的选项卡 6 中
执行前窗口选项卡 6 中的脚本“sh ip int bri”
执行前窗口选项卡 6 中的脚本“”
延迟 0.1
将窗口 1 的选项卡 6 的自定义标题设置为“R6”
告诉应用程序“系统事件”使用击键“t” {command down}
在前窗口的选项卡 7 中执行脚本“telnet localhost 2007” 在前窗口
的选项卡 7 中
执行脚本“”执行脚本“”在前窗口的选项卡 7 中,在前窗口的选项卡 7 中
执行脚本“sh ip int bri”
在前窗口
延迟 0.1的选项卡 7 中执行脚本“”
将窗口 1 的选项卡 7 的自定义标题设置为“SW1”
,使用 {command down} 告诉应用程序“系统事件”击键“t
”在选项卡中执行脚本“telnet localhost 2008”前窗口的 8
执行脚本“”在前窗口的选项卡 8 中
执行脚本“”在前窗口的选项卡 8 中
执行脚本“sh ip int bri | e un”在前窗口的选项卡 8 中
执行脚本“”在前面的选项卡 8窗口
延迟 0.1
将窗口 1 的选项卡 8 的自定义标题设置为“SW2”
告诉应用程序“系统事件”使用 {command down}
do script 击键“t”telnet localhost 2009" 在前窗口的选项卡 9 中
在前窗口的选项卡 9 中执行脚本“在前窗口
的选项卡 9 中执行脚本”在前窗口的选项卡 9 中
执行脚本“sh ip int bri | e un”在前窗口的选项卡 9 中
执行脚本“”在前窗口的选项卡 9 中
延迟 0.1
设置窗口 1 的选项卡 9 到“SW3”的自定义标题
告诉应用程序“系统事件”使用 {command down} 击键“t”
在前面窗口的选项卡 10 中执行脚本“telnet localhost 2010” 在前面的选项卡 10 中
执行脚本“”窗口
执行脚本“”在前窗口的选项卡 10 中
执行脚本“sh ip int bri | e un”在前窗口的选项卡 10 中
执行脚本“”在前窗口
延迟 0.1
的选项卡 10 中,将窗口 1 的选项卡 10 的自定义标题设置为“SW4”
使用 {command down} 告诉应用程序“系统事件”击键“t”
在前窗口的选项卡 11 中执行脚本“telnet localhost 2011” 在前窗口的选项卡 11 中
执行脚本“”在前窗口的选项卡 11 中
执行脚本“”在前窗口的选项卡 11 中
执行前窗口选项卡 11 中的脚本“sh ip int bri | e un”
执行前窗口选项卡 11 中的脚本“”
延迟 0.1
将窗口 1 的选项卡 11 的自定义标题设置为“BB1”,
告诉应用程序“系统事件”为击键“ t" 在前窗口的选项卡 12 中使用 {command down}
执行脚本 "telnet localhost 2012"
执行脚本 " " 在前窗口的选项卡 12 中
执行脚本 "" 在前窗口的选项卡 12 中
在前窗口的选项卡 12 中执行脚本“sh ip int bri” 在前窗口的选项卡 12 中执行脚本“”延迟 0.1 将窗口 1 的选项卡 12 的自定义标题设置为“BB2”
告诉应用程序“系统事件”击键“t”使用 {command down}
在前窗口的选项卡 13 中执行脚本“telnet localhost 2013”​​ 在前窗口的选项卡 13 中
执行脚本“” 在前窗口的选项卡 13 中
执行脚本“”在前窗口的选项卡 13 中
执行脚本“sh ip int bri”前窗在前窗 延迟 0.1的
选项卡 13 中执行脚本“” 将窗口 1 的选项卡 13 的自定义标题设置为“BB3”

结束告诉

于 2013-10-27T16:20:31.630 回答
0

由于需要先打开终端,因此在运行您的工作设置命令之前,只需在顶部添加 cmd 以首先打开终端,作为一种解决方法!

tell application "Terminal" set newTab to do script -- create a new window with no initial command set current settings of newTab to settings set "Grass" end tell

tell application "Terminal" -- the app activate tell application "System Events" to keystroke "n" using {command down} tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2001" in tab 1 of front window do script " " in tab 1 of front window do script " " in tab 1 of front window do script "sh ip int bri " in tab 1 of front window delay 0.1 set custom title of tab 1 of window 1 to "R1" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2002" in tab 2 of front window do script " " in tab 2 of front window do script " " in tab 2 of front window do script "sh ip int bri " in tab 2 of front window do script " " in tab 2 of front window delay 0.1 set custom title of tab 2 of window 1 to "R2" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2003" in tab 3 of front window do script " " in tab 3 of front window do script " " in tab 3 of front window do script "sh ip int bri " in tab 3 of front window do script " " in tab 3 of front window delay 0.1 set custom title of tab 3 of window 1 to "R3" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2004" in tab 4 of front window do script " " in tab 4 of front window do script " " in tab 4 of front window do script "sh ip int bri " in tab 4 of front window do script " " in tab 4 of front window delay 0.1 set custom title of tab 4 of window 1 to "R4" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2005" in tab 5 of front window do script " " in tab 5 of front window do script " " in tab 5 of front window do script "sh ip int bri " in tab 5 of front window do script " " in tab 5 of front window delay 0.1 set custom title of tab 5 of window 1 to "R5" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2006" in tab 6 of front window do script " " in tab 6 of front window do script " " in tab 6 of front window do script "sh ip int bri " in tab 6 of front window do script " " in tab 6 of front window delay 0.1 set custom title of tab 6 of window 1 to "R6" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2007" in tab 7 of front window do script " " in tab 7 of front window do script " " in tab 7 of front window do script "sh ip int bri " in tab 7 of front window do script " " in tab 7 of front window delay 0.1 set custom title of tab 7 of window 1 to "SW1" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2008" in tab 8 of front window do script " " in tab 8 of front window do script " " in tab 8 of front window do script "sh ip int bri | e un" in tab 8 of front window do script " " in tab 8 of front window delay 0.1 set custom title of tab 8 of window 1 to "SW2" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2009" in tab 9 of front window do script " " in tab 9 of front window do script " " in tab 9 of front window do script "sh ip int bri | e un" in tab 9 of front window do script " " in tab 9 of front window delay 0.1 set custom title of tab 9 of window 1 to "SW3" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2010" in tab 10 of front window do script " " in tab 10 of front window do script " " in tab 10 of front window do script "sh ip int bri | e un" in tab 10 of front window do script " " in tab 10 of front window delay 0.1 set custom title of tab 10 of window 1 to "SW4" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2011" in tab 11 of front window do script " " in tab 11 of front window do script " " in tab 11 of front window do script "sh ip int bri | e un" in tab 11 of front window do script " " in tab 11 of front window delay 0.1 set custom title of tab 11 of window 1 to "BB1" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2012" in tab 12 of front window do script " " in tab 12 of front window do script " " in tab 12 of front window do script "sh ip int bri " in tab 12 of front window do script " " in tab 12 of front window delay 0.1 set custom title of tab 12 of window 1 to "BB2" tell application "System Events" to keystroke "t" using {command down} do script "telnet localhost 2013" in tab 13 of front window do script " " in tab 13 of front window do script " " in tab 13 of front window do script "sh ip int bri " in tab 13 of front window do script " " in tab 13 of front window delay 0.1 set custom title of tab 13 of window 1 to "BB3"end tell

于 2014-03-17T17:28:09.633 回答
0

尝试这个...

set shortDelay to 0.2
set tabTitles to {"R1", "R2", "R3", "R4", "R5", "R6", "SW1", "SW2", "SW3", "SW4", "BB1", "BB2", "BB3"}

tell application "Terminal"
    activate
    set frontWindow to window 1
    repeat with i from 1 to 13
        if i is not 1 then
            activate
            tell application "System Events" to keystroke "t" using command down
            delay shortDelay
        end if
        set custom title of tab i of frontWindow to (item i of tabTitles)
        set twoDigits to text -2 thru -1 of ("0" & i)
        do script ("telnet localhost 20" & twoDigits) in frontWindow
    end repeat
end tell
于 2013-10-26T20:53:13.467 回答