On Aug 11, 2011, at 18:08, Roland Küffner wrote:
> one other thing I find myself doing quite often, is that I write one, let's
> say, variable name with a trailing number, copy it down and then, increment
> the number. So, after duplicating one line (with a nice little script) I
> would have a bunch of duplicate lines like:
______________________________________________________________________
Hey Roland,
Script one will operate on the selected variable name OR let you enter a
variable name IF no text is selected.
The format for the dialog is:
variableName<space>startNum<space>endNum
Given that it will produce an enumerated list and replace the selection or
input at the cursor position.
Script two allows you to write the params in BBEdit like so:
someVariableName 1 10
Select the text, and run the script.
If you use Command-L to select the line the script will accommodate to the
carriage return.
--
Best Regards,
Chris
------------------------------------------------------------------------------------------------
set varEnumList to {}
tell application "BBEdit"
try
tell front text window
set selectedText to contents of selection
if length of (words of result) = 1 then
set dialogDefaultAnswer to selectedText & " "
else
set dialogDefaultAnswer to ""
end if
tell me to set varListParams to text returned of ¬
(display dialog "'Variable_Name,Start_Num,End_Num'" default answer
dialogDefaultAnswer)
set AppleScript's text item delimiters to " "
set varListParams to text items of varListParams
if length of varListParams ≠ 3 then
error "Wrong Input!"
else
set {varName, startNum, endNum} to varListParams
repeat with i from startNum to endNum
set end of varEnumList to varName & i
end repeat
set AppleScript's text item delimiters to return
set varEnumList to varEnumList as text
set selection to varEnumList
end if
end tell
on error errMsg number errNum
if errNum ≠ -128 then
set sep to "=============================="
set e to sep & return & "Error: " & errMsg & return & sep & return ¬
& "Error Number: " & errNum & return & sep
beep
display dialog e
end if
end try
end tell
------------------------------------------------------------------------------------------------
set varEnumList to {}
set returnSuffix to false
tell application "BBEdit"
try
tell front text window
set selectedText to contents of selection
if selectedText ends with return then
set selectedText to text 1 thru -2 of selectedText
set returnSuffix to true
end if
if length of (words of selectedText) = 3 then
set AppleScript's text item delimiters to " "
set varListParams to text items of selectedText
set {varName, startNum, endNum} to varListParams
repeat with i from startNum to endNum
set end of varEnumList to varName & i
end repeat
set AppleScript's text item delimiters to return
set varEnumList to varEnumList as text
if returnSuffix = true then
set varEnumList to varEnumList & return
end if
set selection to varEnumList
else
error "Wrong Input!"
end if
end tell
on error errMsg number errNum
set sep to "=============================="
set e to sep & return & "Error: " & errMsg & return & sep & return ¬
& "Error Number: " & errNum & return & sep
beep
display dialog e
end try
end tell
------------------------------------------------------------------------------------------------
--
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>