]> git.lyx.org Git - features.git/commitdiff
Updates to AppleScript support, and documentaoin for it.
authorBenjamin Piwowarski <benjamin@bpiwowar.net>
Wed, 5 Mar 2014 20:46:27 +0000 (15:46 -0500)
committerRichard Heck <rgheck@lyx.org>
Wed, 5 Mar 2014 20:46:27 +0000 (15:46 -0500)
development/MacOSX/LyX.sdef
lib/doc/Additional.lyx
src/support/AppleScript.m

index 41f7408ea5f0b6abb8bf3e3e5565cca418f1b3d2..63b8925b8c853ee1d25db1d53282ad42aeb2c17f 100644 (file)
 -->
  
  
-    <!-- declare the namespace for using XInclude so we can include the standard suite -->
+<!-- declare the namespace for using XInclude so we can include the standard suite -->
 <dictionary xmlns:xi="http://www.w3.org/2003/XInclude">
-        <!-- use XInclude to include the standard suite -->
-    <!-- <xi:include href="file:///System/Library/ScriptingDefinitions/CocoaStandard.sdef" xpointer="xpointer(/dictionary/suite)"/> -->
-        <!-- our special scripting suite for this example -->
-    <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">
+
+       <!-- our special scripting suite for this example -->
+       <suite name="Lyx" code="LYX " description="LyX scripting facilities.">
+               
+          
+               <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"/>
+                               <type type="text" list="no"/>
+                       </direct-parameter>
+                       
+                       <parameter name="with argument" code="args" type="text">
+                               <cocoa key="arg"/>
+                       </parameter>
+                       
+                       <result type="text" description="The message returned by LyX"/>
                </command>
 
-    </suite>
-    
-    
+       </suite>
+       
+       
 </dictionary>
\ No newline at end of file
index 59a31d17eccdb62e563e5d764db8b239cd6edfb4..04f36c80c305df66d571fd40aa57ba3d2ae8fdf8 100644 (file)
@@ -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
index bf06b02d426f0f15d5407d3ec3396d63bb6c326a..324b4beef63c667667f488b604b83f23b936c1c5 100644 (file)
   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