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

时间:2016-01-17 04:04:53

标签: xcode applescript xcode7

我做了一个Applescript,它做了我需要它,但它不断增长。我知道我应该把它放到Xcode中并为它制作一个GUI(我在5年前用另一个做了这个),但是我无法弄清楚基本的布局。有没有人知道使用Applescript在Xcode 7中的基本示例应用程序,这将给我一个起点?有点像,点击按钮和" Hello World"对话框弹出?

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

1 个答案:

答案 0 :(得分:2)

好的,我为你做了一个简单的Xcode项目。单击界面构建器上的按钮时,将显示一个对话框,说明"你好"

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

如果您是Cocoa AppleScript的新手,请注意! Apple Script代码比你在Script Editor中的代码要多得多。

如果Mediafire链接出现故障,以下是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