Basic Xcode 7 使用 Applescript 和 GUI 的示例项目

Basic Xcode 7 example project that uses Applescript and a GUI

我制作了一个 Applescript 可以满足我的需要,但它还在不断增长。我知道我应该把它放入 Xcode 并为它制作一个 GUI(我在大约 5 年前用另一个 GUI 做了这个),但我不太清楚基本布局。有谁知道 Xcode 7 中使用 Applescript 的基本示例应用程序,这会给我一个起点?比如,点击一个按钮,弹出一个 "Hello World" 对话框?

附带问题,学习 Cocoa 或 Swift 而不是使用 Applescript 会更好吗?目前对 iOS 编程不感兴趣。

好的,我已经为您制作了一个简单的 Xcode 项目。单击界面构建器上的按钮时,将显示一个对话框,显示 "hello"

http://www.mediafire.com/download/jpp7cc20t4sbgdg/Example.zip

如果您是 Cocoa AppleScript 的新手,请注意!脚本编辑器中的 AppleScript 代码比您想象的要多得多。

万一 Mediafire link 出现故障,这里是 Xcode 项目中 AppleScript 的内容。

--
--  AppDelegate.applescript
--  Example
--
--  Created by Lucas Sebire on 10/02/2016.
--  Copyright © 2016 Lucasware. All rights reserved.
--

script AppDelegate
    property parent : class "NSObject"

    -- IBOutlets
    property theWindow : missing value

    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_

    on buttonPushed_(sender) -- This is connected to the button on the interface builder

        display dialog "Hello" -- Says Hello

    end buttonPushed_

end script