title: AppleScript to move the mouse and click over specific element in Photoshop
body: <p>I need a little bit of help with my script. Actually i am not sure if the problem is in the script at all or my concept is wrong.
  So, what i am trying to achieve is to automate mouse clicks over two specific positions ( contract and then expand specific tab ) in Photoshop CS6/Cloud..and then return the mouse to the original positions.</p>
  <p><a href="https://i.stack.imgur.com/BmSq0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BmSq0.png" alt="Contract" /></a>
  <a href="https://i.stack.imgur.com/tIak7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tIak7.png" alt="Extend" /></a></p>
  <p>I am using MouseTools and the script works fine when it's not applied in Photoshop but on the Desktop for example.
  The actual problem is that no mouse clicks are executed in Photoshop for some reason. Actually from time to time they are but very rarely. There is no problem with mouse positioning..just with the clicks.
  Here is what i wrote so far :</p>
  <pre><code>set mouseToolsPath to (path to home folder as text) &amp; &quot;UnixBins:MouseTools&quot;
  set {x, y} to paragraphs of (do shell script quoted form of POSIX path of mouseToolsPath &amp; &quot; -location&quot;)
  -- saves the original coordinates in two variables
  set z to x
  set zz to y
  
  tell application &quot;Adobe Photoshop CS6&quot;
      activate
      delay 1
      
      set x to 1838
      set y to 463
      do shell script quoted form of POSIX path of mouseToolsPath &amp; &quot; -x &quot; &amp; (x as text) &amp; &quot; -y &quot; &amp; (y as text) &amp; &quot; -leftClick&quot;
      
      set x to 1799
      set y to 463
      
      do shell script quoted form of POSIX path of mouseToolsPath &amp; &quot; -x &quot; &amp; (x as text) &amp; &quot; -y &quot; &amp; (y as text) &amp; &quot; -leftClick&quot;
      
      set x to z
      set y to zz
      -- returns the mouse in original position
      do shell script quoted form of POSIX path of mouseToolsPath &amp; &quot; -x &quot; &amp; (x as text) &amp; &quot; -y &quot; &amp; (y as text)
  end tell
  </code></pre>
  <p>I have the feeling that i am trying to trick MouseTools that i am on a Desktop and it's getting bugged or something.</p>
  <p>I've already solved this problem with Keyboard Maestro trial version and it works fine .. but since i can't afford to purchase a macro program especially for this problem .. i would like to write a script..and ofc gain some experience myself. :)</p>
  <p>EDIT:
  For the sake of finalising this post .. the temporary solution to this problem for me was a combination of &quot;MouseTools&quot; and &quot;Cliclick&quot;. It works in 9 of 10 times and for some reason only when i run the code via executable made by &quot;Script Editor&quot;. &quot;Automator&quot; runs in properly only when started from inside the GUI of Automator. Automator executable does not run in properly..for some reason. Really strange and buggy behaviour and probably will fail me in time..but still kind of does it's job for now.</p>
  <pre><code>set mouseToolsPath to (path to home folder as text) &amp; &quot;UnixBins:MouseTools&quot;
  set {x, y} to paragraphs of (do shell script quoted form of POSIX path of mouseToolsPath &amp; &quot; -location&quot;)
  
  tell application &quot;Adobe Photoshop CS6&quot;
      activate
      delay 1
      do shell script &quot;/usr/local/bin/cliclick c:1838,463&quot;
      
      delay 0.5
      do shell script &quot;/usr/local/bin/cliclick c:1660,463&quot;
  end tell
  delay 0.5
  do shell script quoted form of POSIX path of mouseToolsPath &amp; &quot; -x &quot; &amp; (x as text) &amp; &quot; -y &quot; &amp; (y as text)
  </code></pre>