title: Cannot run python script with pyautogui as Cron job
body: <p>I've been looking as various ways to fix this issue but cannot find anything that works.</p>
  <p>I can see that the script is running by debugging yet the pyautogui function is not running via Cron. I can confirm the script runs as expected via cli and that the pyautogui module can be seen by cron.</p>
  <p>This is what my cron job looks like for testing.</p>
  <pre><code>* * * * * cd /Users/joeblogs &amp;&amp; python3 ./mouse.py &gt;&gt; /Users/joeblogs/debug.txt 2&gt;&amp;1
  </code></pre>
  <p>This the my script i'm using, it's a very simple script that checks the mouse coordinates then wait 5 seconds and checks again. If the coordinates match the the mouse is moved via pyautogui, if they don't match then the program exits.</p>
  <pre><code>#!/usr/bin/env python3
  import pyautogui
  import time
  import sys
  
  def MovMouse():
  
          prev = pyautogui.position() #Grabs X,Y mouse position
          #print(&quot;position X1 is&quot;, prev[0])
          #print(&quot;position Y1 is&quot;, prev[1])
  
          time.sleep(5)
  
          after = pyautogui.position() #Grabs second X,Y position after 3 seconds
  
          #print(&quot;position X2 is&quot;, after[0])
          #print(&quot;position Y2 is&quot;, after[1])
  
          if (prev == after):
              print (&quot;!!! MOVE MOUSE !!!&quot;)
              pyautogui.moveRel(200, 200)
              #postmove = pyautogui.position
              #print(&quot;position X3 is&quot;, postmove[0])
              #print(&quot;position Y3 is&quot;, postmove[1])
          else:
              print(&quot;Mouse does not need to be moved&quot;)
              sys.exit(0)
  
  
  MovMouse()
  </code></pre>
  <p>I've looked at similar posts like <a href="https://stackoverflow.com/questions/54805988/how-to-make-crontab-run-a-python-script-that-opens-the-terminal-and-does-stuff/54806497">this one</a> but no joy.</p>
  <p>Any help would be great as this issue has been bugging me for a while!</p>
  <p>FYI I'm using the latest version of python3 as of writing this and running in MacOS.</p>
  <p><strong>Solved - I needed to allow accessibility access to cron and my terminal in MacOS settings and now it's working as expexted!</strong></p>