当前行已包含一些文本时在现有终端窗口中运行脚本

发布于 2024-12-21 19:07:05 字数 380 浏览 2 评论 0原文

如果最前面的“终端”选项卡中的当前行包含文本 aa,这将运行命令 aauptime

set cmd to "uptime"
tell application "Terminal"
    try
        do script cmd in window 1
    on error
        do script cmd
    end try
    activate
end tell

您显然可以添加类似 tell app“System Events” 的内容在do script之前使用control down按键“ku”,但是有人知道更好的解决方案吗?

If the current line in the frontmost Terminal tab contained the text aa, this would run the command aauptime:

set cmd to "uptime"
tell application "Terminal"
    try
        do script cmd in window 1
    on error
        do script cmd
    end try
    activate
end tell

You could obviously add something like tell app "System Events" to keystroke "ku" using control down before do script, but does anyone know any better solutions?

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

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

发布评论

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

评论(1

心头的小情儿 2024-12-28 19:07:05

您知道您可以在不瞄准终端的情况下调用 shell 脚本,对吧?

You know you can call a shell script without targeting the terminal, right?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文