title: How can I play an audio file using Raspberry Pi motion? Possible permissions issue?
body: <p>Alright, so here's what I have:</p>
  
  <p>I have a script, called <strong>detect.sh</strong>. This file is located in <strong>/home/pi/detect/detect.sh</strong>. It's permissions are: <strong>-rxwrxwrxw 1 motion motion 66 Feb 19 10:20 /home/pi/detect/detect.sh</strong></p>
  
  <p>This script, contains this code:</p>
  
  <pre><code>#!/bin/sh
  date &gt;&gt; /home/pi/detect/detect_log.txt
  python /home/pi/detect/detect.py
  </code></pre>
  
  <p>As you can see, this script executes my Python script.</p>
  
  <p>My python script is located in <strong>/home/pi/detect/detect.py</strong>, as you can also see. My python script has the following permissions: <strong>-rwxrwxrwx 1 motion motion 178 Feb 19 10:28 /home/pi/detect/detect.py</strong></p>
  
  <p>My Python script contains the following code: </p>
  
  <pre><code>import os
  import subprocess
  
  text_file = open('/home/pi/Desktop/output.txt', 'w')
  text_file.write('Test 1')
  text_file.close()
  
  os.system("sudo aplay /home/pi/detect/bark.wav")
  </code></pre>
  
  <p>When I start motion, using <code>sudo service motion restart</code>, nothing happens. I have, in the configuration file for motion, to </p>
  
  <pre><code>on_event_start sh /home/pi/detect/detect.sh
  </code></pre>
  
  <p>I know this is working. Because my detect_log.txt is created AND updated correctly, which means my script is running. But my python script is not. I do not hear a dog bark, nor is a .txt file created.</p>
  
  <p>Also, my Python script runs when I run it using the standalone module, using Python. I hear a bark and the file is created.</p>
  
  <p>Is this a permissions issue? What is going on? Could it be a permissions for Python issue? I am thoroughly confused, and have been searching for an answer for weeks. Any help is appreciated.</p>