+2011-08-14 Jan Djärv <jan.h.d@swipnet.se>
+
+ * nsterm.h (ns_run_ascript): Declare.
+ (NSAPP_DATA2_RUNASSCRIPT): Define.
+
+ * nsfns.m (as_script, as_result, as_status): New static variables.
+ (ns_run_ascript): New function.
+ (Fns_do_applescript): Set variables as_*. Make an NSApplicationDefined
+ event with data2 set to NSAPP_DATA2_RUNASSCRIPT, post it and then start
+ the event loop. Get status from as_status (Bug#7276).
+
+ * nsterm.m (sendEvent): If event is NSApplicationDefined and
+ data2 is NSAPP_DATA2_RUNASSCRIPT, call ns_run_ascript and then exit
+ the event loop (Bug#7276).
+
2011-08-14 Andreas Schwab <schwab@linux-m68k.org>
* gnutls.c (QCgnutls_bootprop_priority)
extern BOOL ns_in_resize;
+/* Static variables to handle applescript execution. */
+static Lisp_Object as_script, *as_result;
+static int as_status;
/* ==========================================================================
return 0;
}
+/* Helper function called from sendEvent to run applescript
+ from within the main event loop. */
+
+void
+ns_run_ascript (void)
+{
+ as_status = ns_do_applescript (as_script, as_result);
+}
+
DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
doc: /* Execute AppleScript SCRIPT and return the result.
If compilation and execution are successful, the resulting script value
{
Lisp_Object result;
int status;
+ NSEvent *nxev;
CHECK_STRING (script);
check_ns ();
BLOCK_INPUT;
- status = ns_do_applescript (script, &result);
+
+ as_script = script;
+ as_result = &result;
+
+ /* executing apple script requires the event loop to run, otherwise
+ errors aren't returned and executeAndReturnError hangs forever.
+ Post an event that runs applescript and then start the event loop.
+ The event loop is exited when the script is done. */
+ nxev = [NSEvent otherEventWithType: NSApplicationDefined
+ location: NSMakePoint (0, 0)
+ modifierFlags: 0
+ timestamp: 0
+ windowNumber: [[NSApp mainWindow] windowNumber]
+ context: [NSApp context]
+ subtype: 0
+ data1: 0
+ data2: NSAPP_DATA2_RUNASSCRIPT];
+
+ [NSApp postEvent: nxev atStart: NO];
+ [NSApp run];
+
+ status = as_status;
+ as_status = 0;
+ as_script = Qnil;
+ as_result = 0;
UNBLOCK_INPUT;
if (status == 0)
return result;
/* used only in fontset.c */
check_window_system_func = check_ns;
+ as_status = 0;
+ as_script = Qnil;
+ as_result = 0;
}
extern void x_activate_menubar (struct frame *);
extern void free_frame_menubar (struct frame *);
+#define NSAPP_DATA2_RUNASSCRIPT 10
+extern void ns_run_ascript (void);
+
extern void ns_init_paths (void);
extern void syms_of_nsterm (void);
extern void syms_of_nsfns (void);
/* NSTRACE (sendEvent); */
/*fprintf (stderr, "received event of type %d\t%d\n", type);*/
+#ifdef NS_IMPL_COCOA
+ if (type == NSApplicationDefined
+ && [theEvent data2] == NSAPP_DATA2_RUNASSCRIPT)
+ {
+ ns_run_ascript ();
+ [self stop: self];
+ return;
+ }
+#endif
+
if (type == NSCursorUpdate && window == nil)
{
fprintf (stderr, "Dropping external cursor update event.\n");