Hi… I do eBooks and a client has provided me a file where instead of just a “CR” (return) at the end of paragraphs there are lots of instances of a “space return.” I need to remove the extra space char which precedes the CR. Of course, doing a Pages “search and replace” removes the paragraph style.
Please… I need a script which will find “space return” and delete the “space” char.
I’m quite sure that there is a faster scheme but this one do the job.
tell application "Pages" to tell document 1
set lesParagraphes to every paragraph --of body text
repeat with i from 1 to count of lesParagraphes
if text -2 of item i of lesParagraphes is space then
set character -2 of paragraph i to ""
end if
end repeat
end tell
This interesting variation works even when it encounters paragraphs with less than two characters:
tell application "Pages"
tell body text of document 1
set penultimateCharacters to character -2 of paragraphs
repeat with i from 1 to (count penultimateCharacters)
if (item i of penultimateCharacters is space) then
set character -2 of paragraph i to "" -- Or perhaps 'delete character -2 of paragraph i'
end if
end repeat
end tell
end tell
My memory said wrongly that
set penultimateCharacters to character -2 of paragraphs
would fail.
tell application "Pages"
tell body text of document 1
set penultimateCharacters to character -2 of paragraphs
repeat with i from 1 to (count penultimateCharacters)
if (item i of penultimateCharacters is space) then
delete character -2 of paragraph i
end if
end repeat
end tell
end tell