- strcpy (cmd, "xscreensaver-getimage-file --name ");
- s = cmd + strlen (cmd);
+
+# ifdef HAVE_COCOA
+ /* /bin/sh on OS X 10.10 wipes out the PATH. */
+ const char *path = getenv("PATH");
+ char *cmd = s = malloc ((strlen(dir) + strlen(path)) * 2 + 100);
+ strcpy (s, "/bin/sh -c 'export PATH=");
+ s += strlen (s);
+ while (*path) {
+ char c = *path++;
+ if (BACKSLASH(c)) *s++ = '\\';
+ *s++ = c;
+ }
+ strcpy (s, "; ");
+ s += strlen (s);
+# else
+ char *cmd = s = malloc (strlen(dir) * 2 + 100);
+# endif
+
+ strcpy (s, "xscreensaver-getimage-file --name ");
+ s += strlen (s);