mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 13:46:43 +00:00
4674c3e1c5
In order to interact with native osx applications, AppleScript support is a plus. Here is a patch that makes LyX respond to a simple command (run) and that allows to communicate with LyX as with the LyX client. Example of use: tell application "LyX" to run "server-get-filename" with argument ""' returns message:/Users/bpiwowar/newfile1.lyx, code:0 with a message and the error code
47 lines
1.2 KiB
Objective-C
47 lines
1.2 KiB
Objective-C
/**
|
|
* \file AppleScript.m
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author Benjamin Piwowarski
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
#include "AppleScript.h"
|
|
|
|
|
|
|
|
@interface LyxCommand : NSScriptCommand {
|
|
}
|
|
- (id)performDefaultImplementation;
|
|
@end
|
|
|
|
@implementation LyxCommand
|
|
- (id)performDefaultImplementation {
|
|
// Get the command and argument
|
|
NSDictionary * theArguments = [self evaluatedArguments];
|
|
|
|
NSString * directParameter = [self directParameter];
|
|
NSString *arg = [theArguments objectForKey: @"arg"];
|
|
|
|
|
|
// Execute the command
|
|
LyXFunctionResult result = applescript_execute_command([directParameter UTF8String], [arg UTF8String]);
|
|
|
|
// Construct the result record
|
|
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
|
|
|
|
/// Needed by AppleScript in order to discover LyxCommand
|
|
void setupApplescript() {
|
|
}
|
|
|