AppleScript return on random float

2019-08-18 09:05发布

I'm trying to create code in AppleScript that will click my mouse randomly every 1-2 seconds... I want a video game I'm playing to not know or be able to tell that a robot is clicking for me so I need it to be RANDOM... not every second or every 2 seconds but every x seconds where x is a constantly changing variable in-between 1 and 2 seconds... Here is the code so far but it clicks every 1 second:

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

I thought changing the return 1 to return random number 1 to 2 would work

Something like this:

on idle
    tell application "System Events"
        key code 87
    end tell
    set randomDelay to random number from 1 to 2
    return randomDelay
end idle

but it didn't work /:

1条回答
Lonely孤独者°
2楼-- · 2019-08-18 09:28

Make it into

random number from 1.0 to 2.0

If you give integers as the bounds for the random numbers, it will just select random integers. By giving floating point literals, AppleScript switches to giving a random floating point number in the range. From the documentation of random number in the StandardAdditions, it seems that the limits are both inclusive, which is strange for floats but isn't a problem in your case.

查看更多
登录 后发表回答