At 01:08 +0200 on 08/12/2011, =?iso-8859-1?Q?Roland_K=FCffner?= wrote about Incrementing numbers in a rectangular selection:

I tried to come up with a Applescript solution to accomplish it. What I have now is this: I select the '1's in the first block with a rectangular selection. Then, I invoke a script, that increments that numbers by one. Here it is:

tell application "BBEdit"
        set allTargets to selection
        set counter to 0
        repeat with oneTarget in allTargets
                select oneTarget
                try
                        set yeah_tmp to (get (selection as text) + counter)
                        set selection to yeah_tmp as text
                        set counter to counter + 1
                end try
        end repeat
end tell

This works quite well whilst the numbers do not cross a decimal border (9 -> 10, 99 -> 100, etc. - the character count is no longer valid if a former loop instance adds to the amount of existing characters). While this solution is good enough for most of my use cases I thought I might share this with the group and invite more fluent Applescript speakers to improve it.


Assuming that you are have an IF command then just select the text and have the suffixing as + tens + counter. (if you want to go over 99 the have a hundreds also). You set tens and hundreds to "". After the set counter to counter + 1, test for counter=10. If it is, then set counter to 0 and test for tens="", and use the result to set tens to 1 or tens+1. Then if you want to go past 99, do the same test for tens=10 and set hundreds to either 1 or hundreds+1 along with tens=0.

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to