 +  if (*c == '*') c++; // skip optional '*' (for compatibility)
 +  luaL_argcheck(L, *c == 'l' || *c == 'L' || *c == 'a' || lua_isnumber(L, 2), 2,
 +                   "invalid option");
-+#if GTK
++#if (GTK && !__APPLE__)
 +  char *buf;
 +  size_t len;
 +  GError *error = NULL;

+  // Determine process parameters (argv, cwd, envp).
+#if !_WIN32
+  // Construct argv from first string param.
+#if GTK
+  char **argv = NULL;
+  GError *error = NULL;
+  if (!g_shell_parse_argv(luaL_checkstring(L, narg++), NULL, &argv, &error)) {

+      lua_pushvalue(L, -2), lua_pushboolean(L, 1), lua_settable(L, -3);
+      lua_pop(L, 1); // spawn_procs
+      lua_pushnil(L); // no error
+#if (GTK && __APPLE__)
+      // On GTK-OSX, manually monitoring spawned fds prevents the fd polling
+      // aborts caused by GLib.
+      if (!monitoring_fds) g_idle_add(monitor_fds, L), monitoring_fds = 1;
+#endif
+    } else if (pid == 0) {
+      // Child process: redirect stdin, stdout, and stderr, chdir, and exec.
+      close(pstdin[1]), close(pstdout[0]), close(pstderr[0]);
