使用Applescript将命令输入终端但不执行

时间:2014-01-25 06:18:03

标签: macos applescript osx-mavericks

使用Applescript,是否可以打开一个新终端并将命令输入终端但不运行它?

tell application "Terminal"
    do script "echo Hello"
end tell

此代码将在终端中键入行echo Hello并运行它。我们可以避免执行吗?

1 个答案:

答案 0 :(得分:1)

系统事件应用程序和模拟击键的好例子:

tell application "Terminal" to activate -- only needed if Terminal may not be running

tell application "System Events"        
    tell application process "Terminal"
        set frontmost to true
        keystroke "echo Hello"
    end tell        
end tell