Hello!
It was a fun diversion! And I want credit in any doc for your service, should you ever share it!
set AppleScript's text item delimiters to ""
set shortenedText to {}
set thetext to "Here's to the crazy ones. The misfits. The rebels. The troublemakers. The round pegs in the square holes. The ones who see things differently. They're not fond of rules. And they have no respect for the status quo. You can quote them, disagree with them, glorify or vilify them."
set thePars to every paragraph of thetext
repeat with aPar in thePars
set end of shortenedText to everyPeriod from aPar
end repeat
-- Result: "H t t c o. T m. T r. T t. T r p i t s h. T o w s t d. T n f o r. A t h n r f t s q. Y c q t, d w t, g o v t.""H t t c o. T m. T r. T t. T r p i t s h. T o w s t d. T n f o r. A t h n r f t s q. Y c q t, d w t, g o v t."
to everyPeriod from aParagraph
script s
property tPc : " "
end script
iqueue()
set tt to {}
set res to {}
set rParagraph to reverse of every character of aParagraph as text
set ct to count rParagraph
set ofa to offset of "." in rParagraph
set ofb to offset of "!" in rParagraph
set ofc to offset of "?" in rParagraph
set ofs to min3({ofa, ofb, ofc}, {".", "!", "?"}, a reference to s's tPc)
fullPerQadd(contents of s's tPc)
set end of tt to {(ct - ofs + 1)}
set factor to 0
repeat
set ofa to offset of "." in (characters (ofs + 1) through -1 of rParagraph as text)
set ofb to offset of "!" in (characters (ofs + 1) through -1 of rParagraph as text)
set ofc to offset of "?" in (characters (ofs + 1) through -1 of rParagraph as text)
set ofs to min3({ofa, ofb, ofc}, {".", "!", "?"}, a reference to s's tPc)
if ofs is 0 then exit repeat
fullPerQadd(contents of s's tPc)
set factor to factor + ofs + 1
set ofs to factor
set end of tt to {ct - factor + 2}
end repeat
set end of tt to {0}
set tt to reverse of tt
set fullPeriods to {}
repeat with i from 1 to ((get count tt) - 1)
set afullPer to characters (((item i of tt) + 1) as number) thru ((item ((i + 1)) of tt) as number) of aParagraph as text
copy afullPer to end of fullPeriods
end repeat
repeat with afullPer in fullPeriods
set ofs to 0
set factor to 0
set tt to {}
set ct to (get count afullPer)
set rfullPer to reverse of every character of afullPer as text
repeat
set ofa to offset of "," in (characters (ofs + 1) through -1 of rfullPer as text)
set ofb to offset of ";" in (characters (ofs + 1) through -1 of rfullPer as text)
set ofc to offset of ":" in (characters (ofs + 1) through -1 of rfullPer as text)
set ofs to min3({ofa, ofb, ofc}, {",", ";", ":"}, a reference to s's tPc)
if ofs is 0 then exit repeat
perQueueAdd(contents of s's tPc)
set factor to factor + ofs + 1
set ofs to factor
set end of tt to {ct - factor + 2}
end repeat
if tt is not {} then
set tt to {ct} & tt
set end of tt to {0}
set tt to reverse of tt
set Periods to {}
repeat with i from 1 to ((get count tt) - 1)
set per to characters (((item i of tt) + 1) as number) thru ((item ((i + 1)) of tt) as number) of afullPer as text
copy per to end of Periods
end repeat
set np to (get count Periods)
repeat with j from 1 to np
set nw to (get count every word of item j of Periods)
repeat with k from 1 to nw
if k is less than nw then
copy character 1 of word k of item j of Periods to end of res
else if j is less than np then
copy ((character 1 of word k of item j of Periods) & popPerQueue()) to end of res
else
copy ((character 1 of word k of item j of Periods) & popFullPerQueue()) to end of res
end if
end repeat
end repeat
else -- no periods
set wl to every word of afullPer
set nf to (get count wl)
repeat with l from 1 to nf
if l is less than nf then
copy character 1 of word l of afullPer to end of res
else
copy ((character 1 of word l of afullPer) & popFullPerQueue()) to end of res
end if
end repeat
end if
end repeat
set {tids, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
set res to res as text
set AppleScript's text item delimiters to tids
log res
return res
end everyPeriod
on fullPerQadd(athing)
global fullPerqueue
set fullPerqueue to {athing} & fullPerqueue
return contents of item 1 of fullPerqueue
end fullPerQadd
on perQueueAdd(athing)
global perQueue
set perQueue to {athing} & perQueue
return contents of item 1 of perQueue
end perQueueAdd
on popPerQueue()
global perQueue
try
copy (contents of (first item of perQueue)) to queueTop
on error
error "The queue is empty!!!" number 3000
end try
try
set perQueue to rest of perQueue
end try
return queueTop
end popPerQueue
on popFullPerQueue()
global fullPerqueue
try
copy (contents of (first item of fullPerqueue)) to queueTop
on error
error "The queue is empty!!!" number 3000
end try
try
set fullPerqueue to rest of fullPerqueue
end try
return queueTop
end popFullPerQueue
on iqueue()
global perQueue, fullPerqueue
set {perQueue, fullPerqueue} to {{}, {}}
end iqueue
on min(a, b)
if a is less than b then
return a
else
return b
end if
end min
on min3(l, m, n)
set {a, b, c} to {item 1 of l, item 2 of l, item 3 of l}
set {oka, okb, okc} to {false, false, false}
if a is greater than 0 then set oka to true
if b is greater than 0 then set okb to true
if c is greater than 0 then set okc to true
if oka and okb and okc then
set d to min(a, b)
set e to min(b, c)
set f to min(d, e)
if f is a then
set contents of n to contents of item 1 of m
else if f is b then
set contents of n to contents of item 2 of m
else
set contents of n to contents of item 3 of m
end if
return f
else if oka and okb then
set d to min(a, b)
if d is a then
set contents of n to contents of item 1 of m
else
set contents of n to contents of item 2 of m
end if
return d
else if oka and c then
set d to min(a, c)
if d is a then
set contents of n to contents of item 1 of m
else
set contents of n to contents of item 3 of m
end if
return d
else if okb and okc then
set d to min(b, c)
if d is b then
set contents of n to contents of item 2 of m
else
set contents of n to contents of item 3 of m
end if
return d
return min(b, c)
else if oka then
set contents of n to contents of item 1 of m
return a
else if okb then
set contents of n to contents of item 2 of m
return b
else if okc then
set contents of n to contents of item 3 of m
return c
else
return 0
end if
end min3
Result output:
"H t t c o. T m. T r. T t. T r p i t s h. T o w s t d. T n f o r. A t h n r f t s q. Y c q t, d w t, g o v t."