From 908c92e831fd681be37d5decf1e78edbb1bf85ca Mon Sep 17 00:00:00 2001 From: Benjamin Piwowarski Date: Wed, 5 Mar 2014 15:46:27 -0500 Subject: [PATCH] Updates to AppleScript support, and documentaoin for it. --- development/MacOSX/LyX.sdef | 51 ++++++++------------- lib/doc/Additional.lyx | 88 ++++++++++++++++++++++++++++++++++++- src/support/AppleScript.m | 10 ++++- 3 files changed, 113 insertions(+), 36 deletions(-) diff --git a/development/MacOSX/LyX.sdef b/development/MacOSX/LyX.sdef index 41f7408ea5..63b8925b8c 100644 --- a/development/MacOSX/LyX.sdef +++ b/development/MacOSX/LyX.sdef @@ -12,43 +12,28 @@ --> - + - - - - - - - - - - - - - - - - - - - + + + + + + - - - - - - - - + + + + + + + + - - - + + + \ No newline at end of file diff --git a/lib/doc/Additional.lyx b/lib/doc/Additional.lyx index 59a31d17ec..04f36c80c3 100644 --- a/lib/doc/Additional.lyx +++ b/lib/doc/Additional.lyx @@ -131,11 +131,12 @@ End \papercolumns 1 \papersides 2 \paperpagestyle headings -\tracking_changes false +\tracking_changes true \output_changes false \html_math_output 0 \html_css_as_file 0 \html_be_strict true +\author -1762856967 "Benjamin Piwowarski" \end_header \begin_body @@ -5507,6 +5508,91 @@ read a <~/.lyxpipe.out \end_inset echo $a +\change_inserted -1762856967 1393941760 + +\end_layout + +\begin_layout Subsection + +\change_inserted -1762856967 1393941776 +AppleScript (Mac OS X) +\end_layout + +\begin_layout Standard + +\change_inserted -1762856967 1393941776 +Since LyX 2.1, LyX supports basic interactions with AppleScript for normal + communication through the command run. + This command takes a direct argument (the +\series bold +function +\series default + to perform) and an optional argument. + It either returns the output of the function or triggers an error with + the error message and code. +\end_layout + +\begin_layout Standard + +\change_inserted -1762856967 1393941776 +Example: +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 +tell application "LyX" +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + try +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + -- Stores the current file name into f +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + set f to (run "server-get-filename" with argument "") +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + on error the error_message number the error_number +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + display dialog "Error: " & the error_number & ". + " ¬ +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + & the error_message buttons {"OK"} default button 1 +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 + end try +\end_layout + +\begin_layout LyX-Code + +\change_inserted -1762856967 1393941776 +end tell +\change_unchanged + \end_layout \begin_layout Section diff --git a/src/support/AppleScript.m b/src/support/AppleScript.m index bf06b02d42..324b4beef6 100644 --- a/src/support/AppleScript.m +++ b/src/support/AppleScript.m @@ -34,8 +34,14 @@ 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; + if (result.code != 0) { + NSScriptCommand* c = [NSScriptCommand currentCommand]; + [c setScriptErrorNumber:result.code]; + [c setScriptErrorString:message]; + return NULL; + } + + return message; } @end