ASOC application

Hi Everyone,

I am recreating some of my old Applescript Xcode projects to ASOC. I am new to Xcode 3.

The old Xcode install included many Applescript based example projects to get you started.

Does anyone know where I can find an example project that has a NSTable, some text fields and a button where when you fill out a form (text fields) and click the button it adds the record to the NSTable? And then if you click the record in the NSTable it puts the info from the record back into the text fields. ADD, UPDATE, REMOVE record buttons as well.

Any information would be greatly appreciated,
Mike

I don’t think there are any ASOC examples provided by Apple any more. At least, not that I’ve seen.
Everything on ASOC I’ve learned here, and Shane’s book.

Shane Stanley’s book is WELL WORTH the price and there are several table based examples and code samples.

There is one related to contacts, and another for an Automator action, I believe. But that’s pretty much it.

What I think you want to do isn’t hard using bindings. In fact, it can be done with a few property declarations and one line of code:

script AppDelegate
    property parent : class "NSObject"
    property theData:missing value
    property theName:missing value
    property theDept:missing value
    property theYear:missing value
	
	on applicationWillFinishLaunching_(aNotification)
		setTheData_(current application's NSMutableArray's array()) 
	end applicationWillFinishLaunching_
	
end script

You need an array controller, whose content array is bound to the app delegate with the Model Key Path of theData, and then have the table columns’ values bound to the array controller with Controller Key of arrangedObjects and Model Key Paths of theName, theDept and theYear using my example. You also need a button connected to the array controller’s add method and one connected to the remove method. The three text fields would have their values bound to the array controller with a Controller Key of Selection and Model Key Paths of theName, theDept, and theYear. If you select a row, the values will appear in the text fields, and you can then edit those values. If you click on the “add” button, it will give you a new row with the text fields blank, ready to fill in to create the new data.

Ric

That was because studio was living in it’s own world by it’s own rules. Therefore it needed it own documentation and it’s own examples. ASOC is cocoa and as far as I know there are hundred of cocoa examples only written in another syntax (Objective-C mostly).

To make it a little bit more clear is that in the ‘old days’ you wrote


-- in studio
set contents of text field 1 of window 1 to "Hello world!"

In asoc would that be

--textField is a dynamically NSTextField or connected to an text field in an arhcived interface builder file (.xib)
textField's setStringValue_("Hello world!")

The difference is not only the syntax but also the working of it. In the example above the ASOC example isn’t an AppleSciprt command but is recognized by the AppleScriptObjC framework that it is a cocoa object method and therefore is coerced to proper Objective-C code. The studio example is an AppleScript command only usable in the studio environment.

So looking for examples should be searched for cocoa examples and translate them yourself to ASOC. This translation is good enough documented in the release notes. Then the documentation about asoc should also be searched in the cocoa documentation.

Have you actually tried compiling all the sample code in the release notes? (No, some of it doesn’t even compile…)

That’s why I named it translations and not examples…

Nonetheless, the document is wrong. Perhaps more to the point, it leaves out lots of vital information. It doesn’t mention which classes are or are not bridged, it doesn’t mention how to handle out values, it doesn’t mention how to deal with things like NSRects – the list goes on. “good enough”? For someone who already knows Cocoa, perhaps. But for people just coming from ASStudio? You have to be kidding.