Applescript 告诉iTerm打开几个ssh会话

Applescript 告诉iTerm打开几个ssh会话,applescript,iterm,Applescript,Iterm,我使用了一些来自附加URL的简洁示例。到目前为止,我得到的是脚本打开了几个带有ssh会话的选项卡。但由于我有几个客户机,我连接的是他们的服务器,所以我不希望每个客户机都有一个硬编码列表的脚本。我想要一个拨号框,询问我想连接哪个列表 但现在我尝试添加一个对话框,我被卡住了: --set wseServer to {"xen", "bcs", "db", "lx", "mgr", "nx", "proxy", "smb", "wiki", "zarafa"} as list set wseServe

我使用了一些来自附加URL的简洁示例。到目前为止,我得到的是脚本打开了几个带有ssh会话的选项卡。但由于我有几个客户机,我连接的是他们的服务器,所以我不希望每个客户机都有一个硬编码列表的脚本。我想要一个拨号框,询问我想连接哪个列表

但现在我尝试添加一个对话框,我被卡住了:

--set wseServer to {"xen", "bcs", "db", "lx", "mgr", "nx", "proxy", "smb", "wiki", "zarafa"} as list
set wseServer to paragraphs of (do shell script "/bin/cat $HOME/.ssh/hostlist-wse-deb.pssh")
--set edlServer to {"edl", "edev", "edb", "emon"}
set edlServer to paragraphs of (do shell script "/bin/cat $HOME/.ssh/hostlist-edl.pssh")
set allServer to wseServer & edlServer

set serverList to button returned of (display dialog "Dude, choose your prefered connection List" buttons {"wseServer", "edlServer", "allServer"} with title "SSH Server" default button 3 with icon caution giving up after 5)

tell application "iTerm"
activate
set myTerm to (make new terminal)
tell myTerm
    repeat with hostItem in serverList
        set Lsession to (make new session)
        tell Lsession
            --set secureshell to hostItem exec command "ssh " & hostItem
            exec command "ssh " & hostItem
            --sleep to prevent errors if we spawn too fast
            do shell script "/bin/sleep 0.01"
        end tell
    end repeat
end tell
end tell
从对话框中选择一项后,iterm将打开8个选项卡,不执行ssh并关闭它们。。。没有错误,什么都没有

这是我试图扩展的示例:

我知道我快到了,但看不到解决办法

希望你们当中有人能给我一个提示


Thx提前回答我自己,希望它也能帮助其他人:

删除了“告诉应用程序…”上方的所有内容,并添加了以下内容:

set sshList to {"WSE", "EDL", "Alle"}
set sshServer to choose from list sshList with title "SSH Server"
if sshServer = {"WSE"} then set serverList to paragraphs of (do shell script "/bin/cat $HOME/.ssh/hostlist-wse-deb.pssh")
if sshServer = {"EDL"} then set serverList to paragraphs of (do shell script "/bin/cat $HOME/.ssh/hostlist-edl.pssh")
if sshServer = {"Alle"} then set serverList to paragraphs of (do shell script "/bin/cat $HOME/.ssh/hostlist-wse-deb.pssh & /bin/cat $HOME/.ssh/hostlist-edl.pssh")
对话框没有第一次尝试时那么漂亮,但它可以工作。

这可能很有用:

#/usr/bin/osascript
--Applescript启动iterm2终端/选项卡,可配置:
--~命令列表
--~z~颜色
--~Name
--~z~透明度
--~z~缩小
--~水平(h)或垂直(v)拆分行为:(h,v)
--
--使用“osascript”或仅从终端运行/
--执行时不要用鼠标/键盘解除焦点。剧本。
--如果使用了属性,建议全屏显示(CMD+Enter)。
--根据需要更改MyTerm窗口和myItem。
--
--
--作者:路易斯·马丁·吉尔http://www.luismartingil.com
--年份:2013年
告诉应用程序“iTerm”
--第一选项卡
将myItem1设置为{}
将myItem1设置为myItem1&{color:“yellow”,cmds:{“echo yellow”,“ls-lrt”},name:“name_yellow”,trans:“0.1”,zoomout:4,split:“h”}
将myItem1设置为myItem1&{color:“blue”,cmds:{“echo blue1”,“ls-lrt”},name:“name_blue1”,trans:“0.1”,zoomout:2,split:“v”}
将myItem1设置为myItem1&{color:“blue”,cmds:{“echo blue2”,“ls-lrt”},name:“name_blue2”,trans:“0.1”,zoomout:4,split:“v”}
将myItem1设置为myItem1&{color:“blue”,cmds:{“echo blue3”,“ls-lrt”},name:“name_blue3”,trans:“0.1”,zoomout:6}
--第二选项卡
将myItem2设置为{}
将myItem2设置为myItem2&{color:“red”,cmds:{“echo red1”,“ls-lrt”},name:“name_red1”,trans:“0.1”,zoomout:8,split:“h”}
将myItem2设置为myItem2&{color:“red”,cmds:{“echo red2”,“ls-lrt”},name:“name_red2”,trans:“0.1”,zoomout:4}
--第三选项卡
将myItem3设置为{}
将myItem3设置为myItem3&{color:“green”,cmds:{“echo green”,“ls-lrt”},name:“name_green”,trans:“0.1”,zoomout:2,split:“v”}
将myItem3设置为myItem3&{color:“purple”,cmds:{“echo purple”,“ls-lrt”},name:“name_purple”,trans:“0.1”,zoomout:4}
将myTermWindow设置为{myItem1,myItem2,myItem3}
将myterm设置为(创建新终端)
告诉我的期限
重复从1到myTermWindow计数的n
启动会话n
重复i从1到计数(MyTerm窗口的项目n)
--让我们设置实际选项卡的属性
告诉最后一个会话将名称设置为的名称(myTermWindow的项目i)
告诉最后一个会话将背景色设置为的颜色(myTermWindow的项目i的项目n))
告诉最后一个会话将透明度设置为trans of(MyTerm窗口的第i项)
--某些命令可能需要更多的列才能读取
重复zoomout of(myTermWindow的项目i of(项目n))次
使用命令down将术语应用程序“系统事件”告知按键“-”
结束重复
--让我们执行选项卡的命令
在的cmds中使用cmd重复(myTermWindow的第i项)
告诉最后一个会话写入文本cmd
结束重复
--以“D”(垂直)或“D”(水平)方式拆分窗格
如果i小于(myTermWindow的第n项计数),则
如果“h”是(myTermWindow的第i项和第n项)的一部分,则
将split_str设置为“D”
否则,如果“v”被拆分为(myTermWindow的第i项和第n项),则
将split_str设置为“d”
其他的
错误
返回
如果结束
告诉我术语应用程序“系统事件”使用命令down击键split_str
如果结束
结束重复
结束重复
结束语
结束语
#!/usr/bin/osascript
-- Applescript to launch iterm2 terminals/tabs with configurable:
-- ~ List of commands <cmds>
-- ~ Color <color>
-- ~ Name <name>
-- ~ Transparency <trans>
-- ~ Zoom out <zoomout>
-- ~ Split behavior horizontal(h) or vertical(v) <split> :: (h, v)
--
-- Run from terminal with `osascript` or just ./<<script>>
-- Dont unfocus with the mouse/keyboard while executing. the script.
-- Recomended to go full screen (CMD + Enter) if <zoomout> attributes used.
-- Change myTermWindow and myItem(s) as desired.
--
--
-- Author: Luis Martin Gil http://www.luismartingil.com
-- Year : 2013

tell application "iTerm"

    -- First tab
    set myItem1 to {}
    set myItem1 to myItem1 & {{color:"yellow", cmds:{"echo yellow", "ls -lrt"}, name:"name_yellow", trans:"0.1", zoomout:4, split:"h"}}
    set myItem1 to myItem1 & {{color:"blue", cmds:{"echo blue1", "ls -lrt"}, name:"name_blue1", trans:"0.1", zoomout:2, split:"v"}}
    set myItem1 to myItem1 & {{color:"blue", cmds:{"echo blue2", "ls -lrt"}, name:"name_blue2", trans:"0.1", zoomout:4, split:"v"}}
    set myItem1 to myItem1 & {{color:"blue", cmds:{"echo blue3", "ls -lrt"}, name:"name_blue3", trans:"0.1", zoomout:6}}

    -- Second tab   
    set myItem2 to {}
    set myItem2 to myItem2 & {{color:"red", cmds:{"echo red1", "ls -lrt"}, name:"name_red1", trans:"0.1", zoomout:8, split:"h"}}
    set myItem2 to myItem2 & {{color:"red", cmds:{"echo red2", "ls -lrt"}, name:"name_red2", trans:"0.1", zoomout:4}}

    -- Third tab
    set myItem3 to {}
    set myItem3 to myItem3 & {{color:"green", cmds:{"echo green", "ls -lrt"}, name:"name_green", trans:"0.1", zoomout:2, split:"v"}}
    set myItem3 to myItem3 & {{color:"purple", cmds:{"echo purple", "ls -lrt"}, name:"name_purple", trans:"0.1", zoomout:4}}

    set myTermWindow to {myItem1, myItem2, myItem3}

    set myterm to (make new terminal)

    tell myterm
        repeat with n from 1 to count of myTermWindow
            launch session n
            repeat with i from 1 to count of (item n of myTermWindow)
                -- Lets set the properties of the actual tab
                tell the last session to set name to name of (item i of (item n of myTermWindow))
                tell the last session to set background color to color of (item i of (item n of myTermWindow))
                tell the last session to set transparency to trans of (item i of (item n of myTermWindow))
                -- Some commands might require more columns to be readable
                repeat zoomout of (item i of (item n of myTermWindow)) times
                    tell i term application "System Events" to keystroke "-" using command down
                end repeat
                -- Lets execute the commands for the tab
                repeat with cmd in cmds of (item i of (item n of myTermWindow))
                    tell the last session to write text cmd
                end repeat
                -- Split the pane in a "D" (vertical) or "d" (horizontal) way
                if i is less than (count of (item n of myTermWindow)) then
                    if "h" is split of (item i of (item n of myTermWindow)) then
                        set split_str to "D"
                    else if "v" is split of (item i of (item n of myTermWindow)) then
                        set split_str to "d"
                    else
                        error
                        return
                    end if
                    tell i term application "System Events" to keystroke split_str using command down
                end if
            end repeat
        end repeat
    end tell
end tell