]> git.lyx.org Git - lyx.git/blob - src/support/AppleScript.m
Fix quotation marks in PDF TOC
[lyx.git] / src / support / AppleScript.m
1 /**
2  * \file AppleScript.m
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Benjamin Piwowarski
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #import <Cocoa/Cocoa.h>
12 #include "AppleScript.h"
13
14
15
16 @interface LyxCommand : NSScriptCommand {
17 }
18 - (id)performDefaultImplementation;
19 @end
20
21 @implementation LyxCommand
22 - (id)performDefaultImplementation {
23         // Get the command and argument
24         NSDictionary * theArguments = [self evaluatedArguments];
25
26   NSString * directParameter = [self directParameter];
27   NSString *arg = [theArguments objectForKey: @"arg"];
28
29
30   // Execute the command
31   LyXFunctionResult result = applescript_execute_command([directParameter UTF8String], [arg UTF8String]);
32
33   // Construct the result record
34   NSString *message = [NSString stringWithCString:result.message encoding:NSUTF8StringEncoding];
35   free(result.message);
36
37   if (result.code != 0) {
38     NSScriptCommand* c = [NSScriptCommand currentCommand];
39     [c setScriptErrorNumber:result.code];
40     [c setScriptErrorString:message];
41     return NULL;
42   }
43
44   return message;
45 }
46
47 @end
48
49 /// Needed by AppleScript in order to discover LyxCommand
50 void setupApplescript() {
51 }
52