You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Trying to make an autoclicker using apple script

I need to make an auto clicker that clicks on 2 different set locations on the screen, I’ll try to be detailed, but not too much, I don’t mind what code its written in, I just need it to get the job done, the auto clicker is for an application game outside of safari, I basically need it to let my player survive as long as possible (i.e drinking water/eating). I tried using an app like Automator, but instead of actually clicking on the application, it just clicked outside of the app, as if its just hovering and the clicks aren’t registering, I checked out other threads, they gave detailed codes and everything, but when put into apple script, they just dont click, the interval between clicks has to be pretty short, and if it is possible, it would be nice if the clicking only occurred on the specific tab, so that means if I click out or go on a different tab, it would only click on the application and not the screen. Sorry for the big request and paragraph,



Thanks,

MacBook Air 11", macOS 10.15

Posted on Apr 17, 2020 3:21 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 20, 2020 6:36 PM

Yes it is the exact same question but with little details added here and then. And as I said on this thread, i tried to add it on in AppleScript the code would run but none of the code really worked or did what its said to do.. it just did.. nothing.


Edit: sorry for the solved thing, I accidentally pressed it and it doesn't seem to go away.


10 replies
Question marked as Top-ranking reply

Apr 20, 2020 6:36 PM in response to Camelot

Yes it is the exact same question but with little details added here and then. And as I said on this thread, i tried to add it on in AppleScript the code would run but none of the code really worked or did what its said to do.. it just did.. nothing.


Edit: sorry for the solved thing, I accidentally pressed it and it doesn't seem to go away.


Apr 21, 2020 9:38 AM in response to AB1030


My question is, how do I make the code you provided in the previous post work, is there a certain command that I can use for it to be executed correctly?


My script is pretty bare-bones and, in all honesty, would likely need some fleshing out to make a robust solution for all use cases, but I was only intending to show the basic constructs.


You should be able to copy the script as-is, paste it into a new Script Editor.app document and click Run.


From there you can change the script in any way you want - activating specific applications, clicking in different locations, additional delays, etc.

Apr 20, 2020 9:14 PM in response to AB1030

It wasn't clear that you'd run the previous script and it didn't work for you.


There are a few obvious differences between your request and a straightforward 'clicker' script.


For one, you're asking if you can click in a window that isn't frontmost - or, potentially, in a tab that isn't frontmost in a window that also isn't frontmost. There's no way you can click manually in this case (you have to bring the window frontmost for the click to register), and AppleScript is no different.


There may be other approaches that might work - for example, executing a JavaScript .click() command in the relevant tab, but that's nothing I've ever explored.

Apr 29, 2020 9:55 AM in response to Camelot

Oh sorry.. I dabbled a bit in it, and it works, it took me a while to realize that it doesnt move the mouse, you can just move the mouse freely while its clicking.


But now i have found a different problem, is there a way to set a hotkey to start/stop?


Not only that, the game I am playing is in a window and not a browser, and since this code only clicks and since it doesn’t move the mouse and only has a sort of invisible click, It doesn’t register in the game.

May 1, 2020 9:34 AM in response to AB1030

> But now i have found a different problem, is there a way to set a hotkey to start/stop?


You can save any script as a service to make it available in the application Services menu, and you can assign a keystroke to it via System Preferences -> Keyboard -> Shortcuts

That will allow you to invoke the script via a key.


To stop the script, you either need a check within the script loop to see if a key is pressed, or write another script that tells the first script to quit, then setup the second script in the same was you did the first - add it to the services menu.


As for the specifics of your game, you'd need to look more closely at the application's dictionary to determine the best path forward. If a generic click isn't sufficient, you may be able to target a specific window, or UI object (button, checkbox, etc.) within the window. The specifics of this, though, are 100% dependent on the game itself, so I probably can't be specific.

Trying to make an autoclicker using apple script

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.