BBEdit and adding html code

I just moved from a PC to a mac and am just starting to discover (and show my co-workers) what a wonderful life a Mac can be.

I am revising a website and have a LOT of html files that I need to put a single line of html code into. I did this by hand on 15 and decided that maybe I should start to learn a bit of applescript since I have 503 files left to do.

I have a folder that contains several HTML files and 18 subfolders. Each subfolder also contains HTML files. In each one of these files, I have to create a new line add a single line of code on the line before the tag.

I would love to know how to do this using BBEdit and Applescript. Ideally I could give it the root folder for the html files and it would change all files in all folders and subfolders and then give me a list of the files changed.

Is this possible? I figure that this is something I could really show off with to the Windows users in the office since this might be something that might be changed again in the near future. The machine is a a G3 400 running 10.1.5 and bbedit lite 6.1. If needed, I could upgrade the machine to 10.2 or upgrade bbedit also.

Any ideas? Help?

Thanks!
Aaron

You might not need AppleScript in this case because BBEdit is a supreme text editor. If you go to Search menu > Find, the search window will open. It will allow you to define search and replace criteria. At the bottom of the window, it allows you to choose a folder for the action to target. Is the line that you need to create the same for all files? If so, you could define:

Search criteria:
Replace with: your new line

If you need to generate the line dynamically, AppleScript would be the best way to go. BBEdit has excellent AppleScript support.

Regarding BBEdit versions, I don’t know if BBEdit Lite is scriptable or if it has the same setup in the search window. The full version is well worth the investment if you plan to do a lot of work on web sites and text files.

Hi Kleinboy

I once wrote a “script” that uses BBEdit to do the following:

It uses template files for each folder (category) the web-site has and creates a lot of templates therefrom representing the web-site’s folder hierarchy - means, it takes care of folder levels and backwards linking to objects.

Using HTML comments the script can decide whether the HTML code of each site is content or framework and is able to replace the framework using its templates while respecting the position in the folder hierarchy of the page beeing processed.

This way it’s simple to add a new entry to a navigation bar e.g. and let the script update 500 pages with this change.

Best of all: The HTML code of the framework is completely the same inside of the category.

Furthermore you may define exceptions and there is a kind of postprocessing that allows to change single pages individually afterwards.

Last but not least, it does in minutes what people cannot do in weeks, not even errorfree.

Unfortunately to create this it needed weeks of programming and relied on years of AppleScripting know-how and it had never gone public. It was an Inhouse solution for one of my customers - but the I own the rights and the source code :slight_smile:

My script was used to create and update http://www.kinderwelten.de and the structure of the site is likely the same as I designed it in year 2000 still.

This script demonstrates pure AppleScript power and should be released to the public soon, I know… - but it cannot be Freeware, unfortunately, except I become a millionair :wink:

But BBEdit’s built in support is famous too, especially when using GREP ‘search and replace’ over files in folders! - GREP is described in the BBEdit manual and the web.

Have fun with your Mac and be welcome,

Thomas