0

How would I have a button on a local webpage (running locally on localhost) to open a local application on OSX?

I have looked through some answers for windows but can't figure out how to get it to work on OSX.

Run a program from a local webpage

Peyman Mohamadpour
  • 17,954
  • 24
  • 89
  • 100
Matt
  • 41
  • 1
  • 7
  • Why do you say you couldn't figure out how to get those to work on OSX. How did you try them? What happened then? – Alfabravo May 19 '20 at 18:05

1 Answers1

0

I'm using MAMP on my Mac OS X (high sierra), and in PHP the code is :

$command = '/Applications/Safari.app/Contents/MacOS/Safari';
$escaped_cmd = escapeshellcmd($command);
system($escaped_cmd);

Have tested this and it does work in opening up the application locally. You can even call it from the Terminal to test if it works after creating the above code in a .php file.

Example in Terminal on Mas OS X:

php theabovecode.php
Chris Medina
  • 338
  • 1
  • 10
  • how would I turn this into a button you click on the page so it runs the code? – Matt May 18 '20 at 23:40
  • @Matt trying to help. What do you expect to appear on the screen when the button is clicked? – Raptor May 20 '20 at 07:03
  • Just to open the application, i just need to figure out how to integrate this code as i think it works – Matt May 20 '20 at 07:26
  • Either you can use a hyperlink to load the PHP file containing the above codes, or you can use an HTML form (which the action is the PHP file above) and submit the form. In both ways, the page will be blank unless you have something to output in the PHP file, e.g. output some HTML codes, or print some wordings. – Raptor May 20 '20 at 08:30
  • Also, you may also want to write some mechanisms to check whether the program exists and is launched correctly. – Raptor May 20 '20 at 08:32