aboutsummaryrefslogtreecommitdiffstats
path: root/src/nsfns.m
diff options
context:
space:
mode:
Diffstat (limited to 'src/nsfns.m')
-rw-r--r--src/nsfns.m42
1 files changed, 41 insertions, 1 deletions
diff --git a/src/nsfns.m b/src/nsfns.m
index 85246a4c25f..a09011d8461 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -97,6 +97,9 @@ Lisp_Object Fx_open_connection (Lisp_Object, Lisp_Object, Lisp_Object);
97 97
98extern BOOL ns_in_resize; 98extern BOOL ns_in_resize;
99 99
100/* Static variables to handle applescript execution. */
101static Lisp_Object as_script, *as_result;
102static int as_status;
100 103
101/* ========================================================================== 104/* ==========================================================================
102 105
@@ -2052,6 +2055,15 @@ ns_do_applescript (Lisp_Object script, Lisp_Object *result)
2052 return 0; 2055 return 0;
2053} 2056}
2054 2057
2058/* Helper function called from sendEvent to run applescript
2059 from within the main event loop. */
2060
2061void
2062ns_run_ascript (void)
2063{
2064 as_status = ns_do_applescript (as_script, as_result);
2065}
2066
2055DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0, 2067DEFUN ("ns-do-applescript", Fns_do_applescript, Sns_do_applescript, 1, 1, 0,
2056 doc: /* Execute AppleScript SCRIPT and return the result. 2068 doc: /* Execute AppleScript SCRIPT and return the result.
2057If compilation and execution are successful, the resulting script value 2069If compilation and execution are successful, the resulting script value
@@ -2061,12 +2073,37 @@ In case the execution fails, an error is signaled. */)
2061{ 2073{
2062 Lisp_Object result; 2074 Lisp_Object result;
2063 int status; 2075 int status;
2076 NSEvent *nxev;
2064 2077
2065 CHECK_STRING (script); 2078 CHECK_STRING (script);
2066 check_ns (); 2079 check_ns ();
2067 2080
2068 BLOCK_INPUT; 2081 BLOCK_INPUT;
2069 status = ns_do_applescript (script, &result); 2082
2083 as_script = script;
2084 as_result = &result;
2085
2086 /* executing apple script requires the event loop to run, otherwise
2087 errors aren't returned and executeAndReturnError hangs forever.
2088 Post an event that runs applescript and then start the event loop.
2089 The event loop is exited when the script is done. */
2090 nxev = [NSEvent otherEventWithType: NSApplicationDefined
2091 location: NSMakePoint (0, 0)
2092 modifierFlags: 0
2093 timestamp: 0
2094 windowNumber: [[NSApp mainWindow] windowNumber]
2095 context: [NSApp context]
2096 subtype: 0
2097 data1: 0
2098 data2: NSAPP_DATA2_RUNASSCRIPT];
2099
2100 [NSApp postEvent: nxev atStart: NO];
2101 [NSApp run];
2102
2103 status = as_status;
2104 as_status = 0;
2105 as_script = Qnil;
2106 as_result = 0;
2070 UNBLOCK_INPUT; 2107 UNBLOCK_INPUT;
2071 if (status == 0) 2108 if (status == 0)
2072 return result; 2109 return result;
@@ -2670,4 +2707,7 @@ be used as the image of the icon representing the frame. */);
2670 /* used only in fontset.c */ 2707 /* used only in fontset.c */
2671 check_window_system_func = check_ns; 2708 check_window_system_func = check_ns;
2672 2709
2710 as_status = 0;
2711 as_script = Qnil;
2712 as_result = 0;
2673} 2713}