0

Playing with AppleScript I have found when you build a repeat to increment through a block if you cancel it you have to close the script to be able to start over:

property foobar : 0

tell application "BBEdit"
    activate
    select insertion point before first character of text document 1
    repeat
        ## some magic       
    end repeat
end tell

Is there a way on cancel you can reset the property back to 0 in the script so that it can be rerun again? Also, when the repeat loop is ran and finished you still have to close the script to be able to rerun it, even after setting the foobar back to 0 with set foobar to 0. Research didn't show anything on Apple.se, SO, superuser or Apple discussion. How can you get the script to reset without having to close it?

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

2 Answers2

0

You can do this, you will be prompted to restart or cancel the script.

property foobar : 0

tell application "BBEdit"
    activate
    repeat
        set foobar to 0
        select insertion point before first character of text document 1
        repeat
            ## some magic       
        end repeat
        display dialog "Restart Script" buttons {"Cancel", "Restart"} default button 2
    end repeat
end tell
vadian
  • 274,689
  • 30
  • 353
  • 361
-1

I'm confused on what you need the property property foobar : 0 for later in the script. If you just don't make it a property, it resets every time you run the script, so you don't have the problem... but I feel like I've got to be missing something.

I mean, what is that needs to be retained between runs such that you're making foobar an Applescript property, instead of just defining it as a variable?

    set foobar to 0

Let me know what I'm missing here...

LOTUSMS
  • 10,317
  • 15
  • 71
  • 140
Tom Spoon
  • 27
  • 3