在 xcode 中使用 applescript 应用程序在终端中写入

Write in terminal with applescript app in xcode

我想在 Xcode 中使用 applescript 应用程序在终端中写入,但它不起作用。

Applescript 代码:

on ButtonTermialClicked_(sender)
    tell application "Terminal" to activate

    tell application "System Events"
        tell application process "Terminal"
            set frontmost to true
            do shell script keystroke "example text"
        end tell
    end tell
end ButtonTermianlClicked_

提前致谢

编辑:

我想插入的是"chflags hidden"然后隐藏一个文件夹

为什么要使用 GUI 脚本和 System Events? Terminal.app 可编写脚本。

on ButtonTermialClicked_(sender)
     tell application "Terminal"
        activate
        do script "chflags hidden /Users/myself/Desktop/Test" in window 1
     end tell
end ButtonTermianlClicked_

甚至没有Terminal.app

on ButtonTermialClicked_(sender)
    do shell script "chflags hidden /Users/myself/Desktop/Test"
end ButtonTermianlClicked_

/Users/myself/Desktop/Test 表示文件夹的完整路径。如果路径包含 space 个字符,则必须将路径用单引号引起来。