why does the delay in an applescript editor increase by itself?...***

so im trying to write myself a (very simple) auto typer for an mmorpg i play. i found a script for such an application on http://www.sythe.org/archives/438387-how-make-your-own-mac-auto-typer.html and proceeded to edit it for myself. the problem im having is that the delay is set to 3 for every line, but for **** sake, it just keeps slowing down after about a dozen lines. i have tried shortening the application to only 10 lines, and then clicking the continue button, but upon clicking the continue button it simply keeps upping the delay... WHY THE **** MUST YOUR EDITOR NOT WORK APPLE?!?!?!?!?!


and when i had the application set to do about 30 lines, again the frequency of the typing would significantly decrease after it typed my message about a dozen times. my script is as follows:


tell application "System Events"

set texttosay to "Sample Text"


display dialog "Text to say:" default answer ""

set texttosay to the text returned of the result

repeat

activate application "Old School RuneScape"


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn


delay 3


keystroketexttosay


keystrokereturn

display dialog the "Do you want to quit?" buttons {"Continue", "Quit"} default button 1

if the button returned of the result is "Quit" then

exit repeat

end if

end repeat

end tell

MacBook Pro, OS X Mavericks (10.9), fix your mfing AppleScript Editor!!

Posted on Nov 10, 2013 1:59 AM

Reply
21 replies

Nov 12, 2013 10:20 AM in response to ooee5

Applescript with random numbers. You need to vary the return 3.


(*


It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on. Here is an example.



Author: rccharles

For testing, run in the Script Editor.

1) Click on the Event Log tab to see the output from the log statement

2) Click on Run


*)



on run

-- let's get a random number between 1.5 and 3.5

set myRandom to 1.5 + (random number) * 2

log "myRandom = " & myRandom

-- Write a message into the event log.

log " --- Starting on " & ((current date) as string) & " --- "

delay myRandom

-- Write a message into the event log.

log " --- Starting on " & ((current date) as string) & " --- "

end run

Jun 27, 2014 10:35 AM in response to ooee5

Every reply tries to remedy the specific bot-needs of the poster but nobody has yet answered the real question?

Why do the delay commands start adding up?

I have exactly the same problem in every script I write.

I want to process multiple files so I use a repeat function (repeat with aFile in theFiles .... end repeat)

In the repeat function I need the script to wait for some time

So i use a delay p.ex. delay 1

The scripts work, but you notice the delay getting bigger and bigger ...

And they don't just seem to add up, it almost seems to be exponential ...

No problem for 10 files but when I want to process 100 + files it is a nightmare


Does anybody have a clue ?

Jun 27, 2014 11:28 AM in response to gekkodotbe

That doesn't happen with simple scripts that use the delay command, so it must be something specific to what you're doing. If I had to guess (which I do, since I can't see your script) I'd say it was an issue with using the Finder. The Finder's applescript implementation is buggy and prone to unexplainable slow-downs and delays. Try converting your script to use System Events if possible; see if that helps.

Jun 27, 2014 11:51 AM in response to twtwtw

Thanks for the advice,

for now I have given up on the specific script and used other techniques.


Was a script to open illustrator files, outline fonts, outline paths, ... save them as pdf files and combining them in Acrobat pro, and mailing them to workstation.

too long to show all here, but the delays were to be found in system-events tell blocks like this:


tell application "System Events"

keystroke "g" using {shift down, command down}

delay 0.1

keystroke "v" using {command down}

delay 0.1

keystroke return

set the clipboard to newName & theExtension

delay 0.1

keystroke "v" using {command down}

delay 0.1

keystroke return

delay 1

keystroke "w" using {command down}

end tell


pittty I can not select Applescript in the Syntax Highlighting in this editor on this apple website ... :-(


anyhow, if ever one finds the actual cause I would be glad to know ... :-)

Jun 27, 2014 2:04 PM in response to gekkodotbe

It's hard to address a problem neither one of us can currently replicate. 😝 I'll point out the one (very common) mistake you're making, in case it helps on principle. When you GUI script, keep in mind that System Events is a faceless background app (i.e., an app that lacks a GUI) so targeting it with GUI commands can be a foot-in-the-door for unexpected problems. If you're trying to manipulate Illustrator's GUI, then you should use something like:


tell application "System Events"

tell process "Illustrator"


-- put GUI scripting code here

end tell

end tell

That makes sure that the GUI-specific commands are going directly to the app that wants to receive them. It may not make a difference in most cases since SE will pass the commands on to the next app in line anyway, but it's purer code.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

why does the delay in an applescript editor increase by itself?...***

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