打开特定终端风格窗口的Applescript

4

好的,事情是这样的。我希望每个工作都有不同风格的终端窗口。每一个终端窗口将连接到不同的工作,例如,一个将通过ssh连接到一个站点,另一个窗口连接到其他地方等。

所以我想这可以通过一些Applescript来实现?

关键是编写一些Applescript脚本来打开不同的终端窗口。然后将每个脚本添加到快捷方式中。

有任何想法吗?

谢谢 :)


重复(虽然不明显):https://dev59.com/1krSa4cB1Zd3GeqPW35E - Philip Regan
2个回答

3

tell application "System Events" to tell process "Terminal" to click menu bar 1's menu bar item "Shell"'s menu 1's menu item "New Window"'s menu 1's menu item "Grass"

这段代码是用于在终端中打开草窗口的命令。您可以使用此命令来快速打开一个新的终端窗口,以便进行其他操作。
tell application "Terminal"
    set win to do script
    set win's current settings to settings set "Basic"
end tell

1
优秀的解决方案;为了使GUI脚本本地化无关,请使用tell application "System Events" to tell menu 1 of menu item 1 of menu 1 of menu bar item 3 of menu bar 1 of application process "Terminal" to click menu item "Grass"(虽然这依赖于位置,但在这种特定情况下,可以合理地假设它们不会改变;请注意,设置名称本地化)。第二个解决方案的注意事项:在选项卡创建之后应用设置可以工作,但仅适用于视觉属性,而不是行为属性,例如“首选项>设置>Shell”中的“When the shell exits:”设置。 - mklement0

3

如何在终端中设置窗口组?

打开所有所需的终端窗口 --> Shell --> 显示检查器。在设置中,您可以更改每个终端窗口的主题。

窗口 --> 另存为窗口组

在首选项中将启动选项设置为显示该组。

http://img18.imageshack.us/img18/9681/screenshot20111018at110.png http://img542.imageshack.us/img542/9681/screenshot20111018at110.png

如果您想使用Applescript来设置窗口的主题,首先需要使用以下Applescript获取所有主题的ID:
set a to {}
tell application "Terminal"
    repeat with i from 1 to count settings set
        set temp to {settings set i's name, settings set i's id}
        set end of a to temp
    end repeat
    a
end tell

这将输出一个ID #和主题名称的数组。要创建一个新窗口,请使用以下内容:
tell application "Terminal"
    set a to do script "" -- creates new window
    set a's current settings to (settings set id <one of the id #>)
end tell

好的,谢谢你的回答。但我不会同时使用它们。所以我需要分别打开每一个。 - user32004
1
实际上(至少在OS X 10.8中),您可以通过名称引用设置集;例如:set a's current settings to settings set "Grass"。此外,尽管在选项卡创建之后应用设置是有效的,但它仅针对视觉属性而非行为属性,例如“首选项>设置>Shell”中的“When the shell exits:”设置。不幸的是,终端的AppleScript支持不支持使用单个命令创建具有特定设置的窗口(或选项卡)。 - mklement0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接