I have some scripts on my iMac (Yosemite) that work as I expect when called from the terminal but have different results when called from a Python 2.7 program on my Raspberry pi3.
Here is an example: Script on the iMac - this script pauses iTunes; says a phrase; and then restarts iTunes.
saysomething.sh
#!/bin/bash
echo -e "Content-type: text/html\n"
PHRASE=`echo "$QUERY_STRING" | sed -n 's/^.*phrase=\([^&]*\).*$/\1/p' | sed "s/+/ /g" | sed "s/%20/ /g"`
cat << junk
<html>
<head>
<title>
saying
</title>
</head>
<body>
junk
#-----------------------
osascript -e 'tell application "iTunes" to playpause'
osascript -e 'tell application "iTunes" to delay 1'
say "Testing"
#say $PHRASE (line is commented because when run from terminal the param is not passed)
osascript -e 'tell application "iTunes" to delay 2'
osascript -e 'tell application "iTunes" to playpause'
#-----------------------
cat << junk
</body>
</html>
junk
When I run this from a terminal session on the iMac it works as expected, the music playing stops, the word "Testing" is 'said' and then the music restarts.
Python script on the RPI - This script executes the script on the iMac, which I would have thought, would work the same way as it does from the terminal... but it doesn't!
MakeThe_iMac_Say.py
# works with Python 2.7.3
# this script is to have the iMac 'say' the text
#***********************************************
#bring in the required libraries
import urllib2
import os
import string
#***********************************************************
text1 = "hello this is a test"
address = "http://10.0.1.11"
url = address+"/cgi-bin/saysomething.sh?phrase="+text1
response = urllib2.urlopen(url).read()
When I execute this script, from the RPI, the music doesn't pause, and yet the word "Testing" is 'said' (over the music!). So I know that the script on the iMac is in fact running but certain commands are ignored! Note that the 'text1' parameter is currently ignored by the iMac script.
Any thoughts on how I get the script on the iMac to execute the applescript actions when called from the RPI?
edit: The Apache server error log has the following error:
AH01215: execution error: An error of type -10810 has occurred. (-10810): /Library/WebServer/CGI-Executables/saysomethinghttp9.sh
I cannot find anything that explains this error!