Search code examples
applescriptrepeatkeystroke

AppleScript repeat loop gets slower after the first run-through


Working on a project rn and trying to figure out why after the first run the whole thing slows down significantly.

keycode 6 using {shift down} is a shortcut to tell another program to execute. Everything works fine when I run the script but the second repeat the whole execution of the program goes so much slower. But if I physically press down the shortcut on my keyboard the execution goes as fast as the first run. So I don't know what causes this and I really need this to be stable. What's the best solution. Tried different things, like keystroke (keycode 6 using {shift down}), or keystroke "z" using {shift down} or even

key down shift key code 6 key up shift

none of which worked...

Here's the code:

set filepath to (path to me as string) & "Contents:Resources:main.MurGaa"

tell application "Finder"
open alias filepath
end tell



display dialog "How many profiles do you wanna scrape?" default answer "4000"
set banana to text returned of result
set apple to banana / 50

set progress total steps to apple
set a to 0
set progress completed steps to 0
set progress description to "Scraping..."

repeat apple times

set progress additional description to " profiles scraped: " & (a * 50) & " of " & banana
set progress completed steps to a

tell application "System Events"
    with timeout of 300000 seconds
        key code 6 using {shift down}
        delay 300
    end timeout
end tell

set a to a + 1

end repeat

display dialog "Done! Profiles scraped:" & banana

display dialog "If you want to scrape more profiles just restart the app"

quit

Solution

  • So after some trial and error I figured out that it was the other program that I triggered that was getting slowed down because the window was not active. So in the settings of Auto Clicker there was this function to always be in front. I checked that one and now everything works smooth. The script also.

    Thanks for all the help.