0

I have an exec() command on my code which runs an applescript from the desktop

$cmd = "osascript /Users/***/Desktop/script.app";
exec($cmd, $output);
print_r($output);

On one computer it runs without errors, on the second computer it returns an empty array. They are exactly at the same directory, except the username which I change it to the correct one. I also checked the file permissions.

I would appreciate it if someone could shed some light on this one.

Spy
  • 153
  • 10
  • @MarkSetchell for some reason one machine cannot load the applescript from the file. If I write the script inside my code it works perfectly. Your answer was helpful though – Spy Feb 16 '19 at 11:28

1 Answers1

1

The PATH that scripts get exec'ed with may be different on the two machines.

The executable osascript lives at:

/usr/bin/osascript

I guess the machine that works includes /usr/bin in the PATH, and the one that doesn't work doesn't include it.

TL;DR

Give the full path:

$cmd = "/usr/bin/osascript /Users/***/Desktop/script.app";
exec($cmd, $output);
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432