Reputation: 123
I'm trying to automate the click in a certain position of the screen. I found several answers to my question, but none of them helped me.
This command should verify if "Spotify" (it's a random application, just to do a test) is frontmost. If that's true, it should click on a certain position of the screen (in that case, the position of the mouse is on the "play" button). I run the program, everything is going ok. But when i put the application in foreground nothing happen. The program end with "Result: 1"
set x to 0
repeat until x is equal to 1
tell application "System Events"
if frontmost of application "Spotify" is true then
delay (2)
tell application "System Events"
click at {720, 634}
end tell
set x to 1
end if
end tell
end repeat
I also tried to put some "delay", but they've been useless.
Upvotes: 1
Views: 1798
Reputation: 123
Found an alternative way: use python.
To install python, just surf the internet and you'll find out how to do it.
The library I used is "pyAutoGui". To install it just look here: https://pyautogui.readthedocs.io/en/latest/install.html
Then, if you wanna use python and this library on automator, do like this.
Then, if you wanna run your program with a third part library, copy that
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7<< "EOF"
insert your python program and then write "EOF" at the end
Here a little exemple
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7<< "EOF"
import pyautogui
pyautogui.click(720, 634)
EOF
Upvotes: 1