Adding an App Delegate to a Document-Based Application

I believe I successfully added an app delegate to my doc based app (since I can get it to perform test functions on applicationWillFinishLaunching_ for example). However, it doesn’t’ allow me to connect interface elements with the script…

I am trying to add a preference window to the app, so that needs to connect to the APP script/class and not the DOC script/class.


Have you added it to MainMenu.xib?

Clearly not in the correct way…

I added a little blue box and made it the class matching the script/class object. I control dragged the Application icon down to that new blue box and made it a delegate.

Is that the correct procedure? Is there something different to do or some additional step I need to do?

No, that’s correct. Does the new script’s name match the file name? Is it’s parent NSObject?

Meaning the project name? The new script does not match the project or the target name… Is that the problem?

It’s parent is “NSObject”.

Oh, do you mean the script object within the file? Yes, that matches. The file is named “LabelApplication.applescript” and the script inside starts with:

script LabelApplication
	property parent: class "NSObject"

That sounds fine. And I presume it’s in the same .xib as the elements you are trying to connect to. I’m not sure why it’s not working; it works fine here…

I’m not following that… The xib file is there next to the applescript file. The xib is called “MainMenu.xib”.

That’s where the elements exist that I’m trying to connect to…

So, the MainMenu.xib has the blue box of class LabelApplication and that is the application’s delegate. That script (LabelApplication.applescript) is where the elements are that I’m connecting to. However, when I control drag I get nothing… not even an empty menu. Nothing.

What happens if you control-click on the cube representing the app delegate? Does it list its properties?

Yes, it lists:

delegate > application

But if you add a property to it, set to missing value, does it appear?

What elements are you bring to connect?

No… nothing else appears in that list… just that. Adding properties with missing values, don’t show up there.

Did I grab the wrong blue box? It’s just an “Object”.

Just to rule out any naming issues i just named:

¢ TestClass.xib

– The blue box in here is a class TestClass

¢ TestClass.applescript

– This has a script in it called TestClass

You have a couple of problems. (For lurkers, Mark sent me his project.)

First, never rename MainMenu.xib. That’s hard-wired. (OK, it probably can be changed, but it’s a bad idea.)

Second, it looks like you’ve edited your class file in an external editor and saved it with CR line-endings instead of LF. Xcode only deals in LFs, so it’s not seeing your property.

I only renamed it as a last resort…

How do you change the line feed? I think you used to be able to “get info” on a file but I don’t see that anymore.

Got it!!!

Thanks so much for your help.

What a painful day!!!

It should be an option when you save (as) in a script editor.

FWIW, this is one of the reasons I gave AppleScriptObjC Explorer an option to always use LFs when saving .applescript files. When AS compiles, it always returns CRs, but Xcode won’t have a bar of them…