Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TextEdit find/replace script




Le 16 oct. 06 à 13:31, Rob Stott a écrit :

This won't win any prizes, but should do the job...

tell application "TextEdit"
	tell front document
		set theText to text 1
		set text 1 to my replaceTheText(theText, " cie ", " de ")
	end tell
end tell

on replaceTheText(theText, theFromString, theToString)
	tell application "TextCommands"
		search theText for theFromString replacing with theToString
	end tell
end replaceTheText

Thanks a lot Rob. You have shown me the way.

The poblem is that I have other OCR mistakes to corect.

So the script became :

-- Script --
tell application "TextEdit"
tell front document
set theText to text 1
tell application "TextCommands"
set theText to (search theText for " cie " replacing with " de ")
set theText to (search theText for " dc " replacing with " de ")
set theText to (search theText for "N) " replacing with "- ")
set theText to (search theText for " O," replacing with " 0,")
set theText to (search theText for "INDICAnON" replacing with "INDICATION")
set theText to (search theText for " ct " replacing with " et ")
set theText to (search theText for " L5-SI " replacing with " L5- S1 ")
set theText to (search theText for " slir " replacing with " sur ")
set theText to (search theText for " sIIr " replacing with " sur ")
set theText to (search theText for "inteme" replacing with "interne")
set theText to (search theText for "exteme" replacing with "externe")
set theText to (search theText for " ci '" replacing with " d'")
set theText to (search theText for " ci'" replacing with " d'")
set theText to (search theText for " quc " replacing with " que ")
set theText to (search theText for " jc " replacing with " je ")
set theText to (search theText for " nonnal" replacing with " normal'")
set theText to (search theText for " lc " replacing with " le ")
set theText to (search theText for " d '" replacing with " d'")
set theText to (search theText for " l '" replacing with " l'")
end tell
end tell
end tell


-- End of script --

The problem is that the changes are nicely made but only in the result pane. The text stays unchanged. :-(
How can I save those changes to the text.


I have  tried to be less awkward :

-- Script --
set searchList to {" cie ", " dc ", "N) ", " O,", "INDICAnON", " ct ", " L5-SI ", " slir ", " sIIr ", " inteme ", " exteme ", " ci '", " ci'", " quc ", " jc ", " nonnal ", " lc ", " d ' ", " l ' "}
set replaceList to {" de ", "de'", "- ", "0,", "INDICATION", " et ", " L5-S1 ", " sur ", " sur ", " interne ", " externe ", " d'", " d'", " que ", " je ", " normal ", " le ", " d' ", "l'"}
tell application "Tex-Edit Plus"
activate
tell window 1
repeat with x from 1 to the number of items in replaceList
replace replacing with item x in replaceList looking for item x in searchList ¬
with cases matching and whole words matching
end repeat
end tell
end tell


-- End of script --

This does not work at all.

Nothing is simple.
Friendly

Bernard _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden
References: 
 >TextEdit find/replace script (From: Bernard Azancot <email@hidden>)
 >Re: TextEdit find/replace script (From: Rob Stott <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.