打开新的终端窗口,没有按下输入mac

时间:2017-11-19 09:41:00

标签: macos applescript

我想在没有按下命令的情况下打开一个带有“hello world”的新终端窗口,即不按Enter键

我打开终端的新窗口,但我不能写“Hello World”。

怎么做?

代码(在脚本编辑器中):

do shell script "open -a Terminal"

提前致谢。

1 个答案:

答案 0 :(得分:0)

以下示例 AppleScript 代码按您的要求执行:

tell application "Terminal"
    if not (exists window 1) then reopen
    activate
    delay 0.5
    tell application "System Events"
        keystroke "k" using {command down}
        keystroke "Hello World"
    end tell
end tell

注意:根据您系统上的时间调整delay 命令的值。

如果您愿意,也可以使用以下内容:

do shell script "open -a Terminal"
delay 0.5
tell application "System Events"
    keystroke "k" using {command down}
    keystroke "Hello World"
end tell