Updates to AppleScript support, and documentaoin for it.

This commit is contained in:
Benjamin Piwowarski 2014-03-05 15:46:27 -05:00 committed by Richard Heck
parent 3046aa0411
commit 908c92e831
3 changed files with 113 additions and 36 deletions

View File

@ -12,43 +12,28 @@
-->
<!-- 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>

View 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

View File

@ -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