根据使用 Applescript 和最佳实践的内容在终端中选择特定选项卡 [英] Select a particular tab in terminal depending upon the content using applescript and best practices
问题描述
这是一个特定于应用程序的问题.我正在尝试根据其中的内容在 Terminal.app 中查找并选择一个选项卡.这是我正在做的:
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
这不符合预期,而且非常万无一失.我想知道是否有人可以建议一种使用更少代码的方法来做到这一点(例如,循环不应该真的是必要的,但 applescript 是一种难以捉摸的语言).
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).
谢谢
推荐答案
事实是,下面的 Applescript 可以满足您的需求,但是除非您的selectme"字符串非常独特,否则您会在许多选项卡中找到它.但无论如何,给你:
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
这篇关于根据使用 Applescript 和最佳实践的内容在终端中选择特定选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!