根据使用 applescript 的内容和最佳实践,在终端中选择特定选项卡

发布于 2024-10-18 06:41:23 字数 458 浏览 2 评论 0原文

这是一个特定于应用程序的问题。我试图根据其中的内容在 Terminal.app 中查找并选择一个选项卡。这就是我正在做的事情:

tell application "Terminal"
    set foundTabs to (every tab of every window) whose contents contains "selectme"
    repeat with possibleTab in foundTabs
        try
            set selected of possibleTab to true
        end try
    end repeat
end tell

这并不像预期的那样,而且非常万无一失。我想知道是否有人可以建议一种用更少的代码来完成此操作的方法(例如,循环实际上不是必要的,但 applescript 是一种难以捉摸的语言)。

谢谢

This is an application specific problem. I am trying to find and select a tab in Terminal.app depending on contents within. Here is what I'm doing:

tell application "Terminal"
    set foundTabs to (every tab of every window) whose contents contains "selectme"
    repeat with possibleTab in foundTabs
        try
            set selected of possibleTab to true
        end try
    end repeat
end tell

This isn't acting as expected and is pretty foolproof. I wonder if someone can suggest a way to do this with much less code (for instance, the looping shouldn't really be necessary, but applescript is an elusive language).

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-10-25 06:41:24

事实是,以下 Applescript 将执行您想要的操作,但除非您的“selectme”字符串非常独特,否则您会在许多选项卡中找到它。
但无论如何,给你:

tell application "Terminal"
set allWindows to number of windows

repeat with i from 1 to allWindows
    set allTabs to number of tabs of window i
    repeat with j from 1 to allTabs
        if contents of tab j of window i contains "selectme" then
            set frontmost of window i to true
            set selected of tab j of window i to true
        end if
    end repeat
end repeat
end tell

Thing is, the following Applescript will do what you want, but unless your "selectme" string is very unique, you will find it in many tabs.
But anyway, here you go:

tell application "Terminal"
set allWindows to number of windows

repeat with i from 1 to allWindows
    set allTabs to number of tabs of window i
    repeat with j from 1 to allTabs
        if contents of tab j of window i contains "selectme" then
            set frontmost of window i to true
            set selected of tab j of window i to true
        end if
    end repeat
end repeat
end tell
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文