In my living room, I have a Mac Mini I using as both an HTPC as well as a home automation server. The software it uses for the automation is Shion, a free home automation app which is AppleScript capable. On that same Mac Mini, I'm running Apache and have built an interface through which I can send commands. (For what it's worth, the interface is built using jQuery Mobile.)
The trouble I'm running into is that the AppleScripts which work fine in the terminal and in the AppleScript editor are throwing parse errors in the Apache error logs. Since the terminal and AppleScript editor run the script successfully, I would guess the way I've coded my PHP is the problem. But when I check the error logs, it's actually an AppleScript error which shows up.
The AppleScript command is extremely simple:
tell application "Shion"
execute snapshot "Evening Lighting"
end tell
Or even simpler:
tell application "Shion" to execute snapshot "Evening Lighting"
This was the original command I started working with, because I wasn't sure how to use the -e flag to break an AppleScript into multiple lines. When I would paste this into the AppleScript editor or into the terminal, it would execute without any problems. But running it in PHP wouldn't work:
$cmd = "osascript -e 'tell application \"Shion\" to execute snapshot \"Evening Lighting\"'";
exec($cmd);
In the log file, the error the script was returning was "A [sic] identifier can't go after this identifier". This was an AppleScript error which multiple people had run into, but I couldn't find any consistent solutions. The one lead I found was attempting to add 'using terms from application "Shion"' to the beginning of the script, so that it would look like this:
using terms from application "Shion"
tell application "Shion"
execute snapshot "Evening Lighting"
end tell
end using terms from
I had to figure out how to break an AppleScript into multiple lines with osascript, which can be done using the -e flag. If I run this as a regular osascript command, it looks like this:
osascript -e 'using terms from application "Shion"' -e 'tell application "Shion"' -e 'execute snapshot "Evening Lighting"' -e 'end tell' -e 'end using terms from'
Once again, this runs in the terminal with no problem, as well as the AppleScript editor. But now I'm getting a different error in my log: "Expected end of line but found identifier".