emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/nsfns.m,v


From: David Reitter
Subject: [Emacs-diffs] Changes to emacs/src/nsfns.m,v
Date: Tue, 22 Jul 2008 03:15:10 +0000

CVSROOT:        /sources/emacs
Module name:    emacs
Changes by:     David Reitter <davidswelt>      08/07/22 03:15:09

Index: nsfns.m
===================================================================
RCS file: /sources/emacs/emacs/src/nsfns.m,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- nsfns.m     21 Jul 2008 20:27:57 -0000      1.10
+++ nsfns.m     22 Jul 2008 03:15:09 -0000      1.11
@@ -2194,6 +2194,92 @@
    ========================================================================== 
*/
 
 
+#ifdef NS_IMPL_COCOA
+
+/* Compile and execute the AppleScript SCRIPT and return the error
+   status as function value.  A zero is returned if compilation and
+   execution is successful, in which case *RESULT is set to a Lisp
+   string or a number containing the resulting script value.  Otherwise,
+   1 is returned. */
+
+static int
+do_applescript (script, result)
+     Lisp_Object script, *result;
+{
+  NSAppleEventDescriptor *desc;
+  NSDictionary* errorDict;
+  NSAppleEventDescriptor* returnDescriptor = NULL;
+
+  NSAppleScript* scriptObject =
+    [[NSAppleScript alloc] initWithSource:
+                            [NSString stringWithUTF8String: SDATA (script)]];
+
+  returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
+  [scriptObject release];
+  
+  *result = Qnil;
+  
+  if (returnDescriptor != NULL)
+    {
+      // successful execution
+      if (kAENullEvent != [returnDescriptor descriptorType])
+        {
+         *result = Qt;
+         // script returned an AppleScript result
+         if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
+             (typeUTF16ExternalRepresentation 
+              == [returnDescriptor descriptorType]) ||
+             (typeUTF8Text == [returnDescriptor descriptorType]) ||
+             (typeCString == [returnDescriptor descriptorType]))
+           {
+             desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
+             if (desc)
+               *result = build_string([[desc stringValue] UTF8String]);
+           }
+         else
+            {
+             /* use typeUTF16ExternalRepresentation? */
+             // coerce the result to the appropriate ObjC type
+             desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
+             if (desc)
+               *result = make_number([desc int32Value]);
+            }
+        }
+    }
+  else
+    {
+      // no script result, return error
+      return 1;
+    }
+  return 0;
+}
+
+DEFUN ("do-applescript", Fdo_applescript, Sdo_applescript, 1, 1, 0,
+       doc: /* Execute AppleScript SCRIPT and return the result.  If
+compilation and execution are successful, the resulting script value
+is returned as a string, a number or, in the case of other constructs,
+t.  In case the execution fails, an error is signaled. */)
+    (script)
+    Lisp_Object script;
+{
+  Lisp_Object result;
+  long status;
+
+  CHECK_STRING (script);
+  check_ns ();
+
+  BLOCK_INPUT;
+  status = do_applescript (script, &result);
+  UNBLOCK_INPUT;
+  if (status == 0)
+    return result;
+  else if (!STRINGP (result))
+    error ("AppleScript error %d", status);
+  else
+    error ("%s", SDATA (result));
+}
+#endif
+
 DEFUN ("xw-color-defined-p", Fns_color_defined_p, Sns_color_defined_p, 1, 2, 0,
        doc: /* Return t if the current Nextstep display supports the color 
COLOR.
 The optional argument FRAME is currently ignored.  */)
@@ -2554,6 +2640,9 @@
   defsubr (&Sns_list_fonts);
   defsubr (&Sns_font_name);
   defsubr (&Sns_list_colors);
+#ifdef NS_IMPL_COCOA
+  defsubr (&Sdo_applescript);
+#endif
   defsubr (&Sns_color_defined_p);
   defsubr (&Sns_color_values);
   defsubr (&Sns_server_max_request_size);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]