【发布时间】:2011-10-07 20:57:58
【问题描述】:
我正在尝试学习 Applescript,最终以编程方式将终端中选项卡的标题设置为我目前正在使用的任何上下文。应该是一项简单的任务,我几乎已经完成了我认为是的。这是我目前的实验代码...
tell application "Terminal"
activate
set frontIndex to index of the first window whose frontmost is true
tell window frontIndex
set title displays custom title of selected tab to true
set custom title of selected tab to "Bazzy"
end tell
end tell
问题是当我设置选项卡的标题时,所有其他选项卡的标题也会设置。 但是,如果我右键单击并检查一个选项卡,然后在该选项卡上手动设置标题,则在我运行我的代码时它的标题不会受到影响,并且我手动输入的标题仍然存在。好像title displays custom title 属性没有被读取,或者这个属性没有按照我的想法做。
如何将一个标签的标题设置为自定义值?
【问题讨论】:
-
请注意,
set frontIndex to index of the first window whose frontmost is true是不必要的。默认情况下front window或window 1始终是最前面的窗口。 -
在 10.6.8 中,我发现在将“标题显示自定义标题”设置为 true 之前将选项卡/窗口的其他与标题相关的属性设置为 false 很重要:“标题显示设备名称”、“ title 显示 shell 路径”,“title 显示窗口大小”。如果我不这样做,那么另一个布尔值将保持为假,使我的所有标题更新都转到所有窗口的“设置集”,而不是我试图更改的特定窗口/选项卡。适用于 OS X 未来版本的 YMMV。
标签: macos terminal applescript osx-snow-leopard