Applescript repeat ends too early

I'd like to have my computer automatically take a screenshot of a specific webpage and save it to an rtfd document for an hour every five minutes.


However, it seems that I cannot place all of my codes between "repeat 11 times" and "end repeat" as error "Syntax Error; Expected “end” but found “to”." keeps showing up highlighting that "to"


Replacing that "to" with "end" according to the error message will simply end up with a loop for only the "set input method to ABC" section, which is not what I'm expecting.


Please help me figure out whether there's something I've done wrong or it's a Script Editor bug and, if possible, kindly offer a solution.


Much obliged.


Posted on Jan 9, 2019 9:22 AM

Reply
Question marked as Top-ranking reply

Posted on Jan 9, 2019 10:18 AM

Handlers can't be placed in a repeat loop. Move the entire 'to' segment outside it.


(167508)

Similar questions

4 replies

Jan 9, 2019 10:32 AM in response to FeuerStar

Use the note icon (third from right in the editor's bottom toolbar) to post your AppleScript source code. We are not going to type in the code from your images of source code to debug it locally.


Place all of your AppleScript handlers (e.g. goToWebPage) after all of your other AppleScript main body code which you have ended with a return statement:


The AppleScript Commands Guide gives handler examples where the declaration precedes the main code body. My personal preference is trailing AppleScript handlers after the code body. This is the only language where I do this though.


main code

my goToWebPage(homePage)

return


-- separate your handlers from all other main code. The final return will do that.

to goToWebPage(theWebPage)

return

end goToWebPage

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.

Applescript repeat ends too early

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