Integrating Script Debugger with a GUI designed in Xcode

I have never used X-code and also have not written any Applescript for some while as most of my recent coding has been written in Livecode. I believe that Applescript will meet my needs in the future but I wish to use more complex user interfaces than basic Applescript provides.

My Googling led me to this post with the title “using-xcode-cocoa-applescript-asobjc-app-to-provide-rich-gui” which includes a link to a video tutorial by Ben Waldie. In the video he states that Xcode is not the best place to write Applescript so is it possible integrate AppleScript written in Script Debugger with a User Interface built in Xcode by means other than copy and paste?

Best wishes


I’m attempting to follow a Hello World tutorial written by Ben Waldie and I am unable to link the Interface with the Applescript code using the Ctrl drag method in Xcode13 as described in the tutorial.

I realise that this has nothing to do with Script Debugger but hope someone will take pity and offer a solution.


– AppDelegate.applescript
– HelloWorld

– Created by Simon Knight on 28/10/2021.

script AppDelegate
property parent : class “NSObject”

-- IBOutlets
--property theWindow : missing value
property textField : missing value

on buttonClicked_(sender)
      display alert "Hello there " & (stringValue() of textField)
end buttonClicked_

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_

end script

I suspect you’re hitting a bug in Xcode 13.

Let me add a general warning (or two):

You can add fancy interfaces to AppleScript in Xcode, but AppleScript’s memory management makes it unsuitable for anything other than typical one-shot interfaces, such as you might use to define how to process some files, for example. Anything complex or meant to remain running is going to be prone to unexplained crashing.

Also, many of the examples you’re likely to find will be very old (because many people have been bitten by the above, and have therefore abandoned it).

That said, to edit in Script Debugger, you control-click on the file in Xcode’s Project list and choose Open With External Editor. This will open it in Script Debugger, assuming you have set it as the default editor for AppleScript. Just make sure you save after making changes and before switching between the two apps.

Do you mean any AppleScript Xcode app or only those made with Xcode 13?

Dear Mr. Stanley,

Thanks for your warnings which answer a more general question I have about how I will create programs in the future i.e. could Applescript fulfil this role and the answer is probably not.


Yes – with any version of Xcode.

I’ll just back up what Shane says. I’ve spent a lot of time drawing AppleScript projects out of Xcode. Plus, over the last two years I’ve moved away from AppleScript applications, including the much-beloved droplet format. Instead, in order to not have to deal with so many every-changing security issues, I now use .scpt and .scptd files with FastScripts, getting by with either vanilla AS dialogs, or using Shane’s libraries when needed. These have worked very well.

Plus, sometimes, an existing application itself can provide enough of an interface.

1 Like

Maybe a little late to the party.

Recently I have been playing with creating entry forms in Xcode, ASObjC, Swift AppKit, and SwiftUI. These use a combination of AppleScript and Swift for the internal and external interaction.

I can confirm that there is a problem with Xcode 13 in connecting up the button in Ben Waldie’s example app. Not a problem with Xcode 11 or 12.

Currently with the ASObjC app I can interact with external Script Libraries if I provide the necessary privacy and user settings.

I am also able to interact with all three versions of the apps through System Events programming. Gathering data from, setting data in the form, and triggering various controls (buttons, pop up menus, etc.)

What I have been stymied on is attempting to get any of them to accept a Scripting Definition. I have scoured the web for solutions, and was working with Shane’s ASObjC book “AppleScriptObjC Explored 5”. Even with just the simplified sdef mentioned in that chapter I can’t seem to get Script Debugger to recognize the sdef. Yes, I did quit and restart Script Debugger to reload the dictionaries. What is the magic sauce to incorporate scripting dictionaries these days?

I don’t think anything has changed for quite a while. When a dictionary doesn’t load, it’s usually due to a problem in its construction; unfortunately the general lack of feedback is such cases is also unchanged.

That’s disappointing. Here is the error message I get in Xcode after just sending a script that activates the app in Script Debugger.

“A call to OSACopyScriptingDefinition() by NSScriptSuiteRegistry returned an error. Is this application’s OSAScriptingDefinition Info.plist entry valid? If its value is ‘dynamic’, is there an ‘ascr’/‘gsdf’ Apple event handler registered?”

The sdef is currently just the slimmed down one you described in the book which is just Apple’s standard suite with the three properties in the application class. I haven’t added anything else.

What is your entry for OSAScriptingDefinition?

I put both the “Scriptable” as “Yes” and the “Scripting Definition File Name” as the name of the app with the “.sdef” file extension.

It looks like I misread your directions and replaced the name and app code for the Apple defined application suite with my own. Whereas it would seem you meant was to leave that one alone and create a new suite with your own app suite/code.

I can now see the Apple Standard suite in Script Debugger so hopefully can proceed with defining my own classes, properties, enumerations, and commands without too much effort. Wish me luck…

Thanks and sorry about that…