Question about Cocoa scripting
Question about Cocoa scripting
- Subject: Question about Cocoa scripting
- From: Pascal Pochet <email@hidden>
- Date: Mon, 13 May 2002 11:17:39 +0200
I have some problem to get correct results from custom command
created in a myApp.scriptSuite
I want the command to return a custom object of mine, the command is
called and I return my custom object : up there no problem.
But when I assign in Script editor the result to a variable and I try
to access atributes of that variable I got en error "variable not
defined".
tell application "JDBCScriptAgent"
set conn to connect database "avocatdesk" user "postgres"
password "postgres" driver "org.postgresql.Driver" -- as "conn1"
get jdbcconnections
end tell
the result is
{application "JDBCScriptAgent"}
after one run (if I run it more than once I get an array with n times
application "JDBCScriptAgent".
So the positive point is that the count of the array is correct but
what do I forgot to do to get the correct object in it ? Why do I get
the application object instead ?
If I do "get name of conn" I get the "variable conn not defined" error.
I have defined
- (unsigned long)classCode
{
return (unsigned long)'JCon' ;
}
- (NSString *)className
{
return [NSString stringWithCString:"JDBCConnection"] ;
}
in class JDBCConnection
and here is handleConnect from JDBCApplication
-(id)handleConnect:(NSScriptCommand *)command
{
NSDictionary *args = [command evaluatedArguments] ;
NSString *database = [args objectForKey:@"DatabaseName"] ;
NSString *user = [args objectForKey:@"UserName"] ;
NSString *driver = [args objectForKey:@"DriverName"] ;
NSString *password = [args objectForKey:@"Password"] ;
NSString *name = [args objectForKey:@"ConnectionName"] ;
NSLog(@"%@ %@ %@ %@
%@",database,user,password,driver,name) ;
[fConnections addObject: [JDBCConnection
newJDBCConnection:name database:database user:user password:password
driver:driver] ] ;
// [fConnections addObject: name ] ;
return [fConnections lastObject] ;
// return name ;
}
-(NSArray *)jdbcConnections
{
return fConnections ;
}
When I return NSString from handleConnect and modify accordingly the
scriptSuite then everything works ok.
So I supposed there is something to do with JDBCConnection like
implementing one more a protocol, but if this is the problem: which
one ?
I don't have found examples of code regarding returning custom object
to AppleScript events;
Sketch doesn't have any specific commands.
Pascal
PS
Here the scriptSuite
{
"Name" = "JDBCScriptAgent";
"AppleEventCode" = "JDBC";
"Classes" = {
"JDBCApplication" = {
"Superclass" = "NSCoreSuite.NSApplication";
"ToManyRelationships" = {
"jdbcConnections" = {
"Type" = "JDBCConnection";
"AppleEventCode" = "JCon";
"ReadOnly" = "YES" ;
};
};
"AppleEventCode" = "capp";
"SupportedCommands" = {
"JDBCScriptAgent.Connect" = "handleConnect:";
};
};
"JDBCConnection" = {
"Superclass" = "NSCoreSuite.AbstractObject";
"AppleEventCode" = "JCon";
"Attributes" = {
"Status" = {
"Type" = "NSNumber";
"AppleEventCode" = "stat";
};
"Name" = {
"Type" = "NSString";
"AppleEventCode" = "name";
};
"DatabaseName" = {
"Type" = "NSString";
"AppleEventCode" = "dbnm";
};
"UserName" = {
"Type" = "NSString";
"AppleEventCode" = "unam";
};
"DriverName" = {
"Type" = "NSString";
"AppleEventCode" = "drvr";
};
};
};
};
"Commands" = {
"Connect" =
{
"AppleEventClassCode" = "JDBC" ;
"AppleEventCode" = "jdLo" ;
"CommandClass" = "NSScriptCommand" ;
"Type" = "NSObjectReference" ;
"ResultAppleEventCode" = "JCon";
"Arguments" = {
"DatabaseName" = {
"Type" = "NSString" ;
"AppleEventCode" = "DbNm";
};
"UserName" = {
"Type" = "NSString" ;
"AppleEventCode" = "UsNm";
};
"Password" = {
"Type" = "NSString" ;
"AppleEventCode" = "PsWd";
};
"DriverName" = {
"Type" = "NSString" ;
"AppleEventCode" = "DrNm";
};
"ConnectionName" = {
"Type" = "NSString" ;
"AppleEventCode" = "CoNm";
"Optional" = "YES";
};
};
};
};
}
_______________________________________________
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.