I am trying to return an entry in applescript. The current solution is to return an NSDictionary and determine the type of record (Lyx return value) in the sdef file, but this will not work - should I create a specific AppleScript object?
Here is the sdef file
<suite name="Lyx" code="LYX " description="LyX scripting facilities.">
<record-type name="LyX return value" code="LyxR">
<property name="code" code="code" type="integer"
description="Error code (0 in case of success).">
<cocoa key="code"/>
</property>
<property name="message" code="mess" type="text"
description="The returned message.">
<cocoa key="message"/>
</property>
</record-type>
<command name="run" code="SLyxComm" description="run a simple command with one parameter">
<cocoa class="LyxCommand"/>
<direct-parameter description="The command to be executed.">
<type type="text" list="no"/>
</direct-parameter>
<parameter name="with argument" code="args" type="text">
<cocoa key="arg"/>
</parameter>
<result type="LyX return value" description="Contains a code (0 for success) and the message returned by LyX"/>
</command>
</suite>
and here is the objective-C code
@interface LyxCommand : NSScriptCommand {
}
- (id)performDefaultImplementation;
@end
@implementation LyxCommand
- (id)performDefaultImplementation {
NSDictionary * theArguments = [self evaluatedArguments];
NSString * directParameter = [self directParameter];
NSString *arg = [theArguments objectForKey: @"arg"];
LyXFunctionResult result = applescript_execute_command([directParameter UTF8String], [arg UTF8String]);
NSString *message = [NSString stringWithCString:result.message encoding:NSUTF8StringEncoding];
free(result.message);
NSDictionary *objcResult = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:result.code], @"code", message, @"message", nil];
return objcResult;
}
@end
When I try this simple aplescript
tell application "LyX-2.1-qt4"
set x to (run "server-get-filename" with argument "")
end tell
message of x
error: error "Can’t get message of {message:\"\", code:0}." number -1728 from message of {«class mess»:"", «class code»:0}.
source
share