RE: Making an app Scriptable
RE: Making an app Scriptable
- Subject: RE: Making an app Scriptable
- From: "Josh Ferguson" <email@hidden>
- Date: Tue, 25 Feb 2003 13:34:44 -0600
- Priority: normal
- Thread-topic: Making an app Scriptable
Jesus,
The real key to AppleScripting your app is the idea of key-value coding. If you have a variable (myString) in a class that you want to access, then you'll have the two methods - (NSString *)myString and - (void)SetMyString:(NSString *)aString. If you've stuck with this when designing your application, this makes things much easier. With that said, there are a few things that have to happen to enable AppleScript in your application.
1.) Set the key "NSAppleScriptEnabled" to YES in your info.plist. This informs the Finder that your application is indeed applescriptable.
2.) Create two very important files: MyApp.scriptSuite and MyApp.scriptTerminology. The ScriptSuite will tell applescript which objects in your application are open to receiving apple events, and which properties/commands in can manipulate. The ScriptTerminology provides the english version of what's in the ScriptSuite (in other words, the scriptsuite will reference objects and properties at the code level, then the script terminology will convert those objects and properties to a human-readable format...what you're familiar with in AppleScripting).
3.) Once you have the scriptSuite scriptTerminology files created, it's time to fill them. They're your every day XML Plists. The easiest way to get a starting point is to copy them out of the Sketch example (changing the class names where appropriate), or to go to the following URL and go through their example:
http://www.macdevcenter.com/pub/a/mac/2002/02/22/applescript.html?page=3. Once you have this starting point, you can start adding attributes. For information on adding attributes (or really anything else about adding AppleScript to your cocoa app), check out this site:
http://www.stone.com/The_Cocoa_Files/Adding_Applescript.html. When you add an attribute (like myAttribute) to your object in the scriptSuite, it will look for the -myAttribute and -SetMyAttribute methods in that object. Pretty straight forward.
There's really nothing that I can say here that isn't covered in the articles posted above, so I'll avoid a real lengthy post. Just keep in mind that the MVC paradigm is important (especially if you're making a document based app), and that key-value coding is important. They're not imperative, but they'll make your life much easier from an appleScript perspective. To answer your question as specifically as I can, to be able to do something like:
set x to the connection name
You'll have an entry in your scriptTerminology that says that "connection name" maps to connectionName in the MyObject entry in your scriptSuite, then your scriptSuite says that the connectionName attribute of MyObject has this specific apple event code, and that it can be read by accessing the -(NSString *)connectionName method in MyObject. This probably doesn't clear it up much, but like I said...read the articles above and It'll begin to make sense.
Josh Ferguson
MindVision Software
http://filestorm.mindvision.com
-----Original Message-----
From: Jesus De Meyer [
mailto:email@hidden]
Sent: Tuesday, February 25, 2003 12:06 PM
To: Cocoa Development List
Subject: Making an app Scriptable
Hello,
I've been reading the Cocoa docs about making apps Scriptable but
didn't get much wiser. The only thing I remember was that I need some
sort of scriptTerminology file. But I don't know how I can pass data
from my app to a script. For example say I wanted to do this script:
set x to the connection name
how do I pass the connection name from my app?
I'm not very new at AppleScript so you can go all techy. I just don't
get the Cocoa-AppleScript link.
Cheers,
Jesus
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.