Bryan Dease
Bryan Dease

Reputation: 125

How can I launch a local Application on OSX from php running MAMP?

I'm running a bunch of local Kiosks on mac mini's and have been using dropbox to keep all the files in sync. However - the dropbox updates have been sketchy as of late because of the firewall settings where these things are. A workaround I have found is by having dropbox quit and restart periodically to force it to update.

My question is - since all of these are running php applications on MAMP - is there a way to launch a local app from php? I'm able to kill dropbox by doing something like this:

$killit = killall -KILL Dropbox;

But it doesn't work the same to restart it. I've tried doing this:

$start_dbox = open /Applications/Dropbox.app;

To no avail. Is there a better way to automate this process of shutting down and reopening a local application?

Upvotes: 2

Views: 2118

Answers (2)

Bryan Dease
Bryan Dease

Reputation: 125

I was actually able to solve this by creating a shell script with the following:

#!/bin/sh
export DYLD_LIBRARY_PATH=""

osascript -e 'tell application "Dropbox" to activate'

Saved it as start_db.sh and dropped it in my root apache directory (so there was no permissions problem for that user).

Then in my php file I was able to do:

$start_dbox = exec('/full/path/to/start_db.sh');

Worked like a charm. Dropbox now quits and restarts with no issues.

Upvotes: 0

tacocat
tacocat

Reputation: 25

I've had similar problems trying to control software remotely. The 'open' command must be executed either as the currently logged in console user, or from a terminal owned by the console (e.g. Terminal.app).

If you change your PHP to redirect STDERR, you should see the error that 'open' is returning:

$start_dbox = "open /Applications/Dropbox.app 2>&1";

The following text should then be returned from the system call:

LSOpenURLsWithRole() failed with error -10810 for the file /Applications/Dropbox.app.

One workaround I've used in the past is to create a lock file somewhere in the filesystem, which your PHP script can write to and your console user can read. Then, you can create a cron that runs as the console user and periodically checks the lock file to see if it needs to restart Dropbox.

Upvotes: 1

Related Questions