当前行已包含一些文本时在现有终端窗口中运行脚本
如果最前面的“终端”选项卡中的当前行包含文本 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” 的内容在
按键“ku”,但是有人知道更好的解决方案吗?do script
之前使用control down
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您知道您可以在不瞄准终端的情况下调用 shell 脚本,对吧?
You know you can call a shell script without targeting the terminal, right?