maeks84 maeks84 - 20 days ago 6
AppleScript Question

Basic Xcode 7 example project that uses Applescript and a GUI

I made an Applescript that does what I need it to, but it keeps growing. I know I should put it into Xcode and make a GUI for it (I did this ~5 years ago with another one), but I can't quite figure out the basic layout. Does anyone know of a basic example app in Xcode 7 using Applescript, that would give me a starting point to go from? Something like, click a button and a "Hello World" dialog pops up?

Side question, would it be better to learn Cocoa or Swift instead of using Applescript? Not currently interested in iOS programming.

Answer

Ok, I have made a simple Xcode Project for you. When a button on the interface builder is clicked, it will display a dialog saying "hello"

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

If you are new to Cocoa AppleScript, be warned! There is so much more AppleScript Codes than you thought there was in Script Editor.

In case the Mediafire link goes down, here are the contents of the AppleScript that is within an Xcode project.

--
--  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