【问题标题】:Write in terminal with applescript app in xcode在 xcode 中使用 applescript 应用程序在终端中写入
【发布时间】:2019-02-23 18:06:28
【问题描述】:

我想在 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"然后隐藏一个文件夹

【问题讨论】:

    标签: xcode terminal applescript


    【解决方案1】:

    为什么选择 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 表示文件夹的完整路径。如果路径包含空格字符,则必须将路径用单引号括起来。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-23
      • 1970-01-01
      • 2010-09-23
      • 2012-12-24
      • 2011-11-07
      相关资源
      最近更新 更多