Auto Clickers

Joined
May 22, 2017
Messages
6
Reaction score
0
Points
1
I have a little Apple-Script Auto Clicker:

on idle
tell application "System Events"
key code 87
end tell
return 20
end idle

It works, but I would like to make the interval more random, say, a number between 20-25

Can anyone help me with this? Or am I in the wrong area?
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Modify your AppleScript to something like this
Code:
[COLOR=#333333]on idle
[/COLOR] [B] delay (random number from 20 to 25)[/B]
[COLOR=#333333]  tell application "System Events"[/COLOR]
[COLOR=#333333]    key code 87[/COLOR]
[COLOR=#333333]  end tell[/COLOR]
[COLOR=#333333]  return 20[/COLOR]
[COLOR=#333333]end idle[/COLOR]
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,612
Reaction score
1,078
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
@Raz0rEdge I understand about 99% of the script but for my own edification what does the line return 20 do?

Notice the $50.00 word in that sentence just to prove I'm not an idiot? lol
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Sly, in this the script is just returning 20 at the end. Traditionally, scripts return 0 to indicate success and non-zero to indicate failure.
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,612
Reaction score
1,078
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
I get that the script is just returning 20 at the end. So, in this case, its being used as an indicator for whether the script finished successfully?

I really need to find that AppleScript book I bought ages ago. Probably should just buy a new one. That was ages ago.
 
Joined
Oct 16, 2010
Messages
17,540
Reaction score
1,576
Points
113
Location
Brentwood Bay, BC, Canada
Your Mac's Specs
2011 27" iMac, 1TB(partitioned) SSD, 20GB, OS X 10.11.6 El Capitan
I really need to find that AppleScript book I bought ages ago. Probably should just buy a new one. That was ages ago.


Maybe it's in with the books on HyperStacks and hyper script… ;D




Patrick
=====
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,612
Reaction score
1,078
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
Used to have a few of those. I think they now reside with that collection of Microsoft Office manual that took up half a storage shelf. That included an entire book on the Excel macro language. Of course that was in the day when you actually got a paper manuals.
 

chscag

Well-known member
Staff member
Admin
Joined
Jan 23, 2008
Messages
65,248
Reaction score
1,833
Points
113
Location
Keller, Texas
Your Mac's Specs
2017 27" iMac, 10.5" iPad Pro, iPhone 8, iPhone 11, iPhone 12 Mini, Numerous iPods, Monterey
Of course that was in the day when you actually got a paper manuals.

LOL, what are those? I still have my original MS-DOS 6 manual sitting on the shelf along with my Powerpoint manual. :)
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,612
Reaction score
1,078
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
After that version of Office with the half shelf of manuals the next version had all the documentation on CD. I hated that. The CD severely damaged the "stumble upon the answer" factor when it came to the macro language. Oftentimes I'd start with one function in mind as the solution to a problem and after searching the manual found that a related function solved the problem.

PDF-based manuals have almost brought back the stumble upon it factor for me but not quite.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Sorry to correct you RazOrEdge, but the return number in an AppleScript on idle handler, is the number of seconds before the on idle handler runs again.
In the case of the posted code, the on idle handler runs every 20 seconds.

Regards Mark
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Thanks for the clarification Mark, I did't research the entire script, just figured out the random number part..:) Being more familiar with BASH programming, I just assumed it was that, but you are indeed correct with the purpose of the return there.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
I'm glad you took it gracefully, I never liked to correct such a knowledgable contributor on developer forums.

Yeah the Applescript on idle handler is a very unique method.
It's effectively a repeat loop, but allows the user to interact with the rest of the applet, unlike a endless repeat loop which would not.
For the record, the on idle handler has to be in a saved AppleScript application in order to function, and won't run in a plain text AppleScript.

Regards Mark
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
No worries Mark, we all have something to learn and can't be experts in everything. Your posts in this sub-forum are very useful, thus the reason I moved this post here to begin with..:)
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,612
Reaction score
1,078
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
Thanks Mark FX. Makes perfect sense to me. Thanks for the clarification guys.
 
Joined
Oct 16, 2010
Messages
17,540
Reaction score
1,576
Points
113
Location
Brentwood Bay, BC, Canada
Your Mac's Specs
2011 27" iMac, 1TB(partitioned) SSD, 20GB, OS X 10.11.6 El Capitan
I have a little Apple-Script Auto Clicker:


Do I dare ask what this applscript actually does and how is it run or triggered??


Thanks…

- Patrick
======
 

Slydude

Well-known member
Staff member
Moderator
Joined
Nov 15, 2009
Messages
17,612
Reaction score
1,078
Points
113
Location
North Louisiana, USA
Your Mac's Specs
M1 MacMini 16 GB - Ventura, iPhone 14 Pro Max, 2015 iMac 16 GB Monterey
No worries Mark, we all have something to learn and can't be experts in everything. Your posts in this sub-forum are very useful, thus the reason I moved this post here to begin with..:)
:Confused::Confused:Wait just a minute you mean I don't know everything? Not only that I can't know everything no matter how hard I try? But this would mean my wife was right.:Not-Amused:
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,765
Reaction score
2,105
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Do I dare ask what this applscript actually does and how is it run or triggered??


Thanks…

- Patrick
======

The script tell "System Events" to type the number 5 (key code 87) every 20 seconds. You can test this out pretty innoucsouly within Script Editor. Do the following..CMD+space and enter Script Editor. Choose to create New Document and type the following
Code:
tell application "System Events" to key code 87

Now hit enter/return a few times to get some space between that "tell" command and then hit the PLAY button on top (third from the left) and a magic 5 will appear. For each hit of PLAY, you'll get a 5.

This page has a list of all the key codes you can send what the action would be.
 
Joined
Oct 16, 2010
Messages
17,540
Reaction score
1,576
Points
113
Location
Brentwood Bay, BC, Canada
Your Mac's Specs
2011 27" iMac, 1TB(partitioned) SSD, 20GB, OS X 10.11.6 El Capitan
Thanks, I guess. :Blushing:

That page's description comment pretty well describes it for me:
"It's not possible to make any sense out of key code assignments; …" ;)

But maybe I'll dabble around a bit and then I can learn something new and then just maybe I'll be almost as smart as Slydude!!! :Confused:





- Patrick
======
 
OP
B
Joined
May 22, 2017
Messages
6
Reaction score
0
Points
1
Wow! so many responses to such a little thing.

Do I dare ask what this applscript actually does and how is it run or triggered??


Thanks…

- Patrick
======

Sure. It's just a little thing.
It clicks the same spot in a game over and over, about every 20 seconds, or 40-45 seconds, I guess. Because I turn off typing, it clicks instead of typing a 5. It runs/is triggered when I turn on the script. I place the mouse/cursor over the spot I want clicked and then leave it alone.
 
Last edited:

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top