[OS X TeX] Multiple Search/Replace in one script?

Maarten Sneep maarten.sneep at xs4all.nl
Wed May 30 13:49:43 EDT 2007


On May 30, 2007, at 12:50, Steffen Wolfrum wrote:

> TextWrangler would be a nice start.
>
> Could you give me an example how to write a file containing  
> different search/replace runs like ...
>
> search "1. Dezember" 				- replace with "1.\,Dezember" 	- normal
> search "daß" 						- replace with "dass" 			- case insensitive
> search "(\.) ([Dezember|Oktober])	- replace with "\1\\,\2"		- with  
> regular expression

Open TeXtWrangler
Open the AppleScript Editor.
Press the recording button (the circle to the left in the toolbar).
Switch to TextWrangler.
Perform your searches.
Switch back to the script editor and press the stop button (same  
location as the record button)

You should now have a starting point for your scripts:

tell application "TextWrangler"
	activate
	replace "1. Dezember" using "1.\\,Dezember" searching in text 1 of  
text document 1 options {search mode:literal, starting at top:false,  
wrap around:false, backwards:false, case sensitive:false, match  
words:false, extend selection:false}
	replace "daß" using "dass" searching in text 1 of text document 1  
options {search mode:literal, starting at top:false, wrap  
around:false, backwards:false, case sensitive:false, match  
words:false, extend selection:false}
	replace "(\\.) (Dezember|Oktober|Januar|Mai)" using "\\01\\\\,\\02"  
searching in text 1 of text document 1 options {search mode:literal,  
starting at top:false, wrap around:false, backwards:false, case  
sensitive:false, match words:false, extend selection:false}
end tell

Some items ccan be grouped:

tell application "TextWrangler"
	set searchoptions to search mode:literal, starting at top:false,  
wrap around:false, backwards:false, case sensitive:false, match  
words:false, extend selection:false}
	replace "1. Dezember" using "1.\\,Dezember" searching in text 1 of  
text document 1 options searchoptions
	replace "daß" using "dass" searching in text 1 of text document 1  
options searchoptions
	replace "(\\.) (Dezember|Oktober|Januar|Mai)" using "\\01\\\\,\\02"  
searching in text 1 of text document 1 options searchoptions
end tell

This should be your starting point for more advanced scripting.

> ... so that all these will can performed on a file/folder with one  
> call?

This one acts on the front window. Other references, and automator  
will help you with the rest.


HTMH,

Maarten
------------------------- Helpful Info -------------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
TeX FAQ: http://www.tex.ac.uk/faq
List Archive: http://tug.org/pipermail/macostex-archives/
List Reminders & Etiquette: http://www.esm.psu.edu/mac-tex/list/





More information about the MacOSX-TeX mailing list