aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Reitter2008-07-22 03:15:09 +0000
committerDavid Reitter2008-07-22 03:15:09 +0000
commit748766149b657b5e86f861a277e7e054406ec87c (patch)
tree42b4cb489592ab19c6b6a39e2b2c45f6dfc4cf47 /src
parent6a0f0f86fa3b80399f6cd3429e022a95962bc28d (diff)
downloademacs-748766149b657b5e86f861a277e7e054406ec87c.tar.gz
emacs-748766149b657b5e86f861a277e7e054406ec87c.zip
do-applescript: NS version of the Carbon implementation of the same
functionality: execute arbitrary AppleScript code.
Diffstat (limited to 'src')
-rw-r--r--src/nsfns.m89
1 files changed, 89 insertions, 0 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 8bed60a4b4b..40016d9479b 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -2194,6 +2194,92 @@ x_sync (Lisp_Object frame)
2194 ========================================================================== */ 2194 ========================================================================== */
2195 2195
2196 2196
2197#ifdef NS_IMPL_COCOA
2198
2199/* Compile and execute the AppleScript SCRIPT and return the error
2200 status as function value. A zero is returned if compilation and
2201 execution is successful, in which case *RESULT is set to a Lisp
2202 string or a number containing the resulting script value. Otherwise,
2203 1 is returned. */
2204
2205static int
2206do_applescript (script, result)
2207 Lisp_Object script, *result;
2208{
2209 NSAppleEventDescriptor *desc;
2210 NSDictionary* errorDict;
2211 NSAppleEventDescriptor* returnDescriptor = NULL;
2212
2213 NSAppleScript* scriptObject =
2214 [[NSAppleScript alloc] initWithSource:
2215 [NSString stringWithUTF8String: SDATA (script)]];
2216
2217 returnDescriptor = [scriptObject executeAndReturnError: &errorDict];
2218 [scriptObject release];
2219
2220 *result = Qnil;
2221
2222 if (returnDescriptor != NULL)
2223 {
2224 // successful execution
2225 if (kAENullEvent != [returnDescriptor descriptorType])
2226 {
2227 *result = Qt;
2228 // script returned an AppleScript result
2229 if ((typeUnicodeText == [returnDescriptor descriptorType]) ||
2230 (typeUTF16ExternalRepresentation
2231 == [returnDescriptor descriptorType]) ||
2232 (typeUTF8Text == [returnDescriptor descriptorType]) ||
2233 (typeCString == [returnDescriptor descriptorType]))
2234 {
2235 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2236 if (desc)
2237 *result = build_string([[desc stringValue] UTF8String]);
2238 }
2239 else
2240 {
2241 /* use typeUTF16ExternalRepresentation? */
2242 // coerce the result to the appropriate ObjC type
2243 desc = [returnDescriptor coerceToDescriptorType: typeUTF8Text];
2244 if (desc)
2245 *result = make_number([desc int32Value]);
2246 }
2247 }
2248 }
2249 else
2250 {
2251 // no script result, return error
2252 return 1;
2253 }
2254 return 0;
2255}
2256
2257DEFUN ("do-applescript", Fdo_applescript, Sdo_applescript, 1, 1, 0,
2258 doc: /* Execute AppleScript SCRIPT and return the result. If
2259compilation and execution are successful, the resulting script value
2260is returned as a string, a number or, in the case of other constructs,
2261t. In case the execution fails, an error is signaled. */)
2262 (script)
2263 Lisp_Object script;
2264{
2265 Lisp_Object result;
2266 long status;
2267
2268 CHECK_STRING (script);
2269 check_ns ();
2270
2271 BLOCK_INPUT;
2272 status = do_applescript (script, &result);
2273 UNBLOCK_INPUT;
2274 if (status == 0)
2275 return result;
2276 else if (!STRINGP (result))
2277 error ("AppleScript error %d", status);
2278 else
2279 error ("%s", SDATA (result));
2280}
2281#endif
2282
2197DEFUN ("xw-color-defined-p", Fns_color_defined_p, Sns_color_defined_p, 1, 2, 0, 2283DEFUN ("xw-color-defined-p", Fns_color_defined_p, Sns_color_defined_p, 1, 2, 0,
2198 doc: /* Return t if the current Nextstep display supports the color COLOR. 2284 doc: /* Return t if the current Nextstep display supports the color COLOR.
2199The optional argument FRAME is currently ignored. */) 2285The optional argument FRAME is currently ignored. */)
@@ -2554,6 +2640,9 @@ be used as the image of the icon representing the frame. */);
2554 defsubr (&Sns_list_fonts); 2640 defsubr (&Sns_list_fonts);
2555 defsubr (&Sns_font_name); 2641 defsubr (&Sns_font_name);
2556 defsubr (&Sns_list_colors); 2642 defsubr (&Sns_list_colors);
2643#ifdef NS_IMPL_COCOA
2644 defsubr (&Sdo_applescript);
2645#endif
2557 defsubr (&Sns_color_defined_p); 2646 defsubr (&Sns_color_defined_p);
2558 defsubr (&Sns_color_values); 2647 defsubr (&Sns_color_values);
2559 defsubr (&Sns_server_max_request_size); 2648 defsubr (&Sns_server_max_request_size);