【发布时间】:2015-11-01 03:29:05
【问题描述】:
我正在使用 Xcode 7 开发一个 Cocoa Applescript 应用程序。该应用程序将运行简单的终端命令,例如 $ cd、$ ls、$ ./name 等。
我的问题是如何在 GUI 窗口的 textView 字段中显示终端结果(例如,当我键入“ls”时,它会显示我当前目录的内容列表)。
screenshot of my simple application
script AppDelegate
property parent : class "NSObject"
-- IBOutlets
property theWindow : missing value
on changedirectoryClicked_(sender)
tell application "Terminal"
activate
do script "cd"
end tell
end changedirectoryClicked_
on ifconfigClicked_(sender)
tell application "Terminal"
activate
do script "ifconfig"
end tell
end ifconfigClicked_
on exitClicked_(sender)
tell application "Terminal"
activate
do script "exit"
end tell
end exitClicked_
on lsClicked_(sender)
tell application "Terminal"
activate
do script "cd"
end tell
end lsClicked_
on applicationWillFinishLaunching_(aNotification)
-- Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
结束脚本
【问题讨论】:
标签: macos cocoa terminal applescript