i am new to the world of cocoa programming, i want to add applescript support to my app. Also the example at apple's website seems out of date
I found this tutorial useful in the past. It is written with Core Data in mine, but should be easily converted to any Cocoa based app.
You should read the Cocoa Scripting Guide on Apple's DevCenter.
You'll want to start with Introduction to AppleScript Overview.
EDIT: If you want some sample code, you can head to Mac OS X Reference Library:Interapplication Communication and filter the list with 'Sample Code'. I tried the Cocoa Sample application called Sketch under Xcode 3.2 and it works.
Modern versions of Cocoa can directly interpret the scripting definition (.sdef) property list, so all you need to do for basic AppleScript support is to create the sdef per the docs, add it to your "copy bundle resources" phase and declare AppleScript support in your Info.plist. To access objects other than NSApp, you define object specifiers, so each object knows its position in the scripting world's hierarchy. That gets you kvc manipulation of object properties, and the ability to use object methods as simple script commands.
The best place to look for on the subject is the Mac OS X Reference Library.
Here is all the information that you will need to get started:
This sample walks you through the most basic steps required to make an application scriptable. This includes setting up the info.plist file, adding a scripting dictionary, and adding a property to the main application class.
This sample is a follow-on to the SimpleScripting and SimpleScriptingProperties sample and it shows how to add an object hierarchy to the terminology provided by a AppleScriptable application.
This sample is a follow-on to the SimpleScripting sample and it shows how to add some properties to the terminology provided by a AppleScriptable application.
This sample is a follow-on to the SimpleScripting sample and it shows how to add some verbs to the terminology provided by a AppleScriptable application.
This sample is a follow-on to the SimpleScriptingObjects sample, and it uses many of the techniques from the SimpleScriptingVerbs sample. After completing the steps defined in the SimpleScriptingObjects sample to set up and create a scriptable application, you can continue with the steps in this sample to add both scripting plugin capabilities to the application and an example scripting plugin.
The techniques presented here illustrate a number of interesting things you can do with a scripting plugin. These include:
(a) adding new scripting classes
(b) extending existing scripting classes
(c) adding new scripting commands
Briefly said, once an application is scriptable, allowing for scripting plugins is easy work. The modifications to the host application are minimal and very generic. No special code needs to be added to the existing scripting classes to allow for plugins. And, creating the scripting plugins is no more difficult than adding some additional scripting to the application. The scripting plugin itself is a simple Cocoa Loadable Bundle that contains one or more .sdef files describing its scripting functionality.