Hi Guys,
I got this below script from net which is closer to my need. I like to run this script in MS Word for all the paragraph in the document. i.e., text string is to be a paragraph and to loop each and every paragraph in the Word Document.
Can anyone help me please?
I got this below script from net which is closer to my need. I like to run this script in MS Word for all the paragraph in the document. i.e., text string is to be a paragraph and to loop each and every paragraph in the Word Document.
Code:
set theText to "The #quick brownfox jumps in over the" & tab & "lazy dog. The quick #brk own fox jumps over the lazy" & tab & "dog."
Can anyone help me please?
Code:
set theText to "The #quick brownfox jumps in over the" & tab & "lazy dog. The quick #brk own fox jumps over the lazy" & tab & "dog."
set astid to AppleScript's text item delimiters
-- Break the text at the hashes and the tabs, assuming that they occur alternately and that the first hash occurs before the first tab.
set AppleScript's text item delimiters to {"#", tab}
set textItems to theText's text items
-- Preset a "<\\b>" delimiter.
set AppleScript's text item delimiters to "<\\b>"
-- Edit the even-numbered text items as required.
repeat with i from 2 to (count textItems) by 2
-- Get a text item to be edited.
set textBetweenDelims to item i of textItems
set len to (count textBetweenDelims)
-- Initialise a collector for the segments of ten or fewer characters.
set edits to {}
-- Initialise start and end indices for the segments.
set j to 1
set k to 10
-- Extract the segments from this text item.
repeat until (k > len)
-- Reduce k until a space is found.
repeat until (item k of textBetweenDelims is space)
set k to k - 1
-- If k reaches j, abandon the search for a space and use 10 characters anyway.
if (k = j) then
set k to j + 9
exit repeat
end if
end repeat
-- Append each segment to the collector.
set end of edits to text j thru k of textBetweenDelims
-- Reset the indices to get the next segment.
set j to k + 1
set k to j + 9
end repeat
-- Append any remaining text from the text item to the collector.
if (j ≤ len) then set end of edits to text j thru len of textBetweenDelims
-- Replace the original text item with text consisting of "#", the segments (coerced to text with the "<\b>" delimiter), and a tab.
set item i of textItems to "#" & edits & tab
end repeat
-- Coerce the edited text-item list to a new text.
set AppleScript's text item delimiters to ""
set newText to textItems as text
set AppleScript's text item delimiters to astid
return newText
--> "The #quick <\\b>brownfox <\\b>jumps in <\\b>over the lazy dog. The quick #brk own <\\b>fox jumps <\\b>over the <\\b>lazy dog."