Re: Weird behavior of text in Pages
Re: Weird behavior of text in Pages
- Subject: Re: Weird behavior of text in Pages
- From: "Stockly, Ed" <email@hidden>
- Date: Fri, 01 Aug 2014 19:45:41 +0000
- Thread-topic: Weird behavior of text in Pages
I found the script from years ago that had the issue I mentioned. It's not
exactly as I described it. There's a mistake in the script below so that
when the TIDs are set in the first group they actually have double braces
{{tid}} for both find and replace. It separates the text into a list just
fine, but reforms the text as if the TIDs were set to "" (and empty string).
In the second group the find TIDs still have double braces, but the replace
TIDs have single braces {tid}, and it works as expected.
I thought I'd found a bug in BBEdit as this was running on a BBEdit window,
but below is the script I used to figure out it was a bug of my own making.
ES
--------------
set aStringToFix to "Here's text. It needs to be fixed! Right now, fix it."
set {doubleBrace, singleBrace} to SlugifyText(aStringToFix)
display dialog "Double Brace: " & doubleBrace & return & return & "Single
Brace: " & singleBrace
--DoubleBrace version is bad; singleBraceVersion is good
on SlugifyText(textForSlug)
set Brace2Text to ReplaceInText(textForSlug, {" "}, {"--"})
set Brace2Text to ReplaceInText(Brace2Text, {"'"}, {"--"})
set Brace2Text to ReplaceInText(Brace2Text, {"."}, {"--"})
set Brace2Text to ReplaceInText(Brace2Text, {","}, {"--"})
set Brace2Text to ReplaceInText(Brace2Text, {"!"}, {"--"})
set Brace2Text to ReplaceInText(Brace2Text, {"----"}, {"--"})
set Brace1Text to ReplaceInText(textForSlug, {" "}, "-")
set Brace1Text to ReplaceInText(Brace1Text, {"'"}, "")
set Brace1Text to ReplaceInText(Brace1Text, {"."}, "-")
set Brace1Text to ReplaceInText(Brace1Text, {","}, "-")
set Brace1Text to ReplaceInText(Brace1Text, {"!"}, "-")
set Brace1Text to ReplaceInText(Brace1Text, {"--"}, "-")
return {Brace2Text, Brace1Text}
end SlugifyText
on ReplaceInText(textToFix, find, replace)
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {find}
set textToFix to every text item of textToFix
set AppleScript's text item delimiters to {replace}
set fixedText to textToFix as text
set AppleScript's text item delimiters to oldDelims
return fixedText
end ReplaceInText
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden