Search code examples
xcodecocoauser-interfaceapplescript-objc

Cocoa-Applescript: Placing a GUI in an applescript


OK so this is my first Xcode project, and I am making a new application from an existing applescript, using Cocoa-applescript to make a GUI for it (thats the major change). I read up on all I could find about GUIs in cocoa applescript, and I wanted to convert this:

choose from list baseactions with title "Version Control" default items defaultaction with prompt "What do you want to do?" OK button name "Go" cancel button name "Quit"
set choice1 to result as string
if choice1 = false then
    error number -128
else if choice1 = "Make New Project" then
    set thechoice to "new"
else if choice1 = "Edit Existing Project" then
    set choice2 to button returned of (display dialog "What would you like to do with the existing Project?" buttons {"Quit", "Make new version", "Create Project Folder"} default button 3 with title "Version Control" with icon "Icon.png")
    if choice2 = "Quit" then
       error number -128
    else if choice2 = "Create Project Folder" then
       set thechoice to "folder"
    else if choice2 = "Make new version" then
       set thechoice to "version"
    end if
else if choice1 = "Change Settings" then
    set thechoice to "settings"
end if

to a GUI in which instead of multiple dialog boxes, it is one smooth GUI in which when you press a button, depending on which is pressed, it sets 'thechoice' to either "new", "folder", "version" or "settings" and then the rest of the script continues off that. I have already made the GUI in Xcode: [I don't have enough reputation to post pictures, but the GUI looks like this:

Make New Project
Import to Existing Project
Edit Existing Project

Settings

and linked each button to a handler (eg the "Make New Project" button):

on NewProject_(sender)
    set thechoice to "new"
end

And similar handlers for each button. The problem is, after I press the button, it doesn't continue with the rest of the script - it just stops. So for anyone who knows how Cocoa-Applescripts work, I would really appreciate it.


Solution

  • For a beginner's intro to ASOC, please watch the "INTRO VIDEO" here: http://www.macosxautomation.com/applescript/develop/index.html or go here: http://asobjcresources.weebly.com

    Or read Shane Stanley's excellent book "AppleScriptObjC Explored", which you can buy on-line right under the intro video box listed above.