The other day I was searching for tutorials on the internet on how to create an automatic mouse clicker with Apple Script, but I just couldn’t find anything that worked. Some websites said it was possible by telling process “X” to call the function click, like so:
I tried it but it didn’t really work. The thing is that click can only click on UI elements of MacOSX Applications, but if you want to click in say a flash program running in a website you will have a hard time.
The next best thing that I found along my journey was this blog post. In it the author explains how he needed an automatic mouse clicker that could interact with videogame interface elements. This was just what I needed, since the Apple Script “click” function cannot interact with all UI elements. The solution was the following,
This code would have to be saved in a file called "click.m" and then compiled as
“gcc -o click click.m -framework ApplicationServices -framework Foundation” If there are no errors an executable named “click” should be produced. To call it, you should be in the same directory as the executable and you call it as such,
Note: XCoordinate and YCoordinate should be changed to the desired values.
An automatic mouse clicker script can now be written pretty easily in Apple Script, all we have to do is to call the executable with the “do shell script” command.
Note: "Users/berny/Documents/workspace-dev/Apple_Scripts/click" should be changed to the directory where the click executable is stored.
You can use other Apple Script commands if for example you want to click an area of the screen every N seconds:
This is how I was able to make a script that clicks a button in a flash program every 6 seconds. I hope you found this blog post useful, if you have questions or need further help you can contact me at bernyoviedo@utexas.edu