TextWrangler applescript

HI
I need to constantly clean up files in Textwrangler
I need to open the files in the same window
The search replace patterns are always the same
Recording my script is useless because while the pattern is the same the filenames in the open window are always different
Is there a way to do something like this:

tell application “TextWrangler”
activate
replace "/2015 " using “/2015\r” saving no searching in

Every open document in the currently open window

options {search mode:literal, case sensitive:false, match words:false, extend selection:false, showing results:true}
end tell

Thanks

Hi. Try text documents.

tell application "TextWrangler"
	replace "/2015 " using "/2015\\r" saving no searching in text documents options {search mode:literal, case sensitive:false, match words:false, extend selection:false, showing results:true}
end tell

Thanks but it doesn’t work

Is there a literal forward slash before the actual 2015 text? If not, your search term shouldn’t include it. Post a snippet of the text you are searching and your version info.

Thanks I found the solution
I used the year 2015 only as an example: in fact I always have several search replace patterns
This is the proper script working for TextWrangler useres


tell application "TextWrangler"
	tell front project window to set docList to its text documents
	repeat with i in docList
		tell i's text to replace "text to replace" using "new text" options ¬
			options {search mode:literal, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end repeat
end tell



Thanks for your attempt to help

Hi Danwan,

I had problems when compiling your code.
I think it’s because you have the keyword ‘options’ twice in the line of code within the repeat loop.


tell application "TextWrangler"
	tell front project window to set docList to its text documents
	repeat with i in docList
		tell i's text to replace "text to replace" using "new text" options ¬
			{search mode:literal, case sensitive:false, match words:false, extend selection:false, showing results:true}
	end repeat
end tell

Most of the options you’re using are defaults and thus unnecessary.


tell application "TextWrangler"
    repeat with i in (get text documents of front project window)
        tell i's text to replace "Now" using "¢¢¢" options {starting at top:true}
    end repeat
end tell

[code]-------------------------------------------------------
TEXTWRANGLER REPLACE-OPTIONS DEFAULTS

backwards (false)
case sensitive (false)
extend selection (false)
match words (false)
returning results (false)
search mode (literal)
showing results (true)
starting at top (false)
wrap around (false)[/code]

  • Adam “ code tags are not displaying as it should (e.g. preformatted).


Chris


{ MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.11.1 }
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯