Quantcast

Forums | MacLife

You are not logged in.

#1 2007-05-24 10:33 am

lord funk
Title
Registered: 2000-12-11
Posts: 2276

Batch process HTML files?

What's the best way to batch process HTML files?  All I need to do is a Find/Replace for each one a couple of times and save.  Is this something Automator can do?  I can use Dreamweaver at my university, if that's better.

Thanks.


In and around the lake,
Mountains come out of the sky
And they stand there!

Offline

 

#2 2007-05-24 11:16 am

registered_user
bulletproof
From: padding: zero-pixels;
Registered: 2000-12-19
Posts: 16026
Website

Re: Batch process HTML files?

I use Textwrangler.

You can find and replace on entire directories.  It's very slick and very free.  It even handles grep should you feel inclined to use regex.

And it's fast, unlike Textmate which would better off not having a Find / Replace feature than its current one.

Last edited by registered_user (2007-05-24 11:17 am)

Offline

 

#3 2007-05-24 4:39 pm

lord funk
Title
Registered: 2000-12-11
Posts: 2276

Re: Batch process HTML files?

Cool, thanks!


In and around the lake,
Mountains come out of the sky
And they stand there!

Offline

 

#4 2007-05-25 5:30 am

W2ttsy
Member
Registered: 2002-03-04
Posts: 3294

Re: Batch process HTML files?

you can open all your files with Dreamweaver too, then do your find and replace and then save all... wouldnt recommend it. last time i tried that i almost melted the computer to the desk. 467, 000 HTML pages had to have 2 lines of code changed. gotta love govt sites.

W2ttsy


http://img5.photobucket.com/albums/v15/collateral187/Misc/evil-fingers2.gif punk! http://members.cox.net/registered_user/maxes/big/rockon.gif

modding is for rich smurfs, hacking is for pov asses like me

Offline

 

#5 2007-05-25 7:57 pm

chipper
Member
From: Abroad
Registered: 2001-08-29
Posts: 251
Website

Re: Batch process HTML files?

registered_user

i'm a textmate user myself - i like it a lot actually. but i have to agree that it's Find In Project function is pretty frustrating to use. it's apparently getting revamped in version 2, but that won't come out until Leopard does (sigh).

i tried textwrangler, and just couldn't get into it. but, you can't argue with free. i was just used to textmate by then, I think.

W2ttsy - that is one of the things that I did truly like about dreamweaver - the find and replace, that is. that's the way it should work, in my opinion. but i've only worked on small sites - not thousands of pages. i don't think any program would deal well with that may documents. yikes!

Offline

 

#6 2007-05-25 8:24 pm

registered_user
bulletproof
From: padding: zero-pixels;
Registered: 2000-12-19
Posts: 16026
Website

Re: Batch process HTML files?

I'd probably swear by textmate if I could find and replace with it.

But I can't.  Not even with plain string replacement not to mention regex.  And that's a feature that's just too critical to abandon.

Textmate sits in my dock at home though.  If they fix it, I may even get a license for work.

Offline

 

#7 2007-05-26 9:39 am

Rozzlapeed
Born to be IT
From: Scottsdale, AZ
Registered: 2003-01-02
Posts: 1095
Website

Re: Batch process HTML files?

Type this into the Terminal:

Code:

man sed

"He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife."
-- Douglas Adams, The Hitch Hiker's Guide to the Galaxy

Offline

 

#8 2007-05-26 9:52 am

registered_user
bulletproof
From: padding: zero-pixels;
Registered: 2000-12-19
Posts: 16026
Website

Re: Batch process HTML files?

how primitive!

Offline

 

#9 2007-05-27 7:46 am

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Batch process HTML files?

W2ttsy wrote:

you can open all your files with Dreamweaver too, then do your find and replace and then save all... wouldnt recommend it. last time i tried that i almost melted the computer to the desk. 467, 000 HTML pages had to have 2 lines of code changed. gotta love govt sites.

You don't  have to open them all and save them all.  There is an option in the find/replace to perform the process on a folder or site.  It actually works quite nicely.


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#10 2007-05-27 7:51 am

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Batch process HTML files?

registered_user wrote:

And it's fast, unlike Textmate which would better off not having a Find / Replace feature than its current one.

Sadly, even on a small site it can bring the app to its knees.  I switch to BBEdit for site wide stuff.


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#11 2007-05-27 7:55 am

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Batch process HTML files?

registered_user wrote:

I'd probably swear by textmate if I could find and replace with it.

But I can't.  Not even with plain string replacement not to mention regex.  And that's a feature that's just too critical to abandon.

You realize, if you just do things correctly the first time, you wouldn't have to rely so heavily on find/replace.


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#12 2007-05-27 9:07 am

spinner
Member
From: Australia
Registered: 2000-10-18
Posts: 276
Website

Re: Batch process HTML files?

TextWrangler, or BBEdit would be my pick.  Use something with Regular Expressions and you can even do this for more complex changes.  sed is another good choice, but not exactly friendly.

I haven't used textmate, but get the feeling I should give it a look...

Offline

 

#13 2007-05-27 10:06 am

registered_user
bulletproof
From: padding: zero-pixels;
Registered: 2000-12-19
Posts: 16026
Website

Re: Batch process HTML files?

Scott wrote:

You realize, if you just do things correctly the first time, you wouldn't have to rely so heavily on find/replace.

javascript:insert_text(':squint:',%20'');
javascript:insert_text(':fister:',%20'');

Offline

 

#14 2007-05-28 8:36 am

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Batch process HTML files?

spinner wrote:

...Use something with Regular Expressions and you can even do this for more complex changes.

Isn't that pretty much available in every text editor?  I can't think of one that doesn't have it.  (except textedit)

spinner wrote:

I haven't used textmate, but get the feeling I should give it a look...

It simply rocks.  But as pointed out, best use TW or something if you have to batch change stuff, or like Roo and make a lot of mistakes. 

Personally, if I am having to clean up a bunch of files or convert them I like DreamWeaver.  DW goes fast enough, but mainly it has some nice simple tools for building 'patterns'.  Like removing all comments, or specific tags, or swapping tags, or removing/changing attributes of tags, applying formatting, etc.


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#15 2007-05-29 8:42 pm

chipper
Member
From: Abroad
Registered: 2001-08-29
Posts: 251
Website

Re: Batch process HTML files?

I am not an ubergeek coder type - i mainly just do front-end HTML/CSS. I probably leave 95% of textmate's abilities untouched. but for what I do need, it's great, albeit a little rough around the edges. the thing that i really like, and the reason i use it instead of textwrangler or other editors, is bundles. bundles are commands that you can put together and assign your own key command for them. that's just huge for me. for instance, i set up some simple commands that insert the proper HTML code for special typographic pieces - like real quote marks (and not tick marks). in messing around with other programs, i didn't find that i could do it as easily. i also enjoy being able to modify the screen/text colors to my liking. superficial, but important to me.

there are several things about textmate that i don't like, but aren't enough to get me to switch to something else:
-Find in Project is still wonky - sometimes it adds code bits from other searches for no discernible reason
-There is a bundle command to open the current document in a running browser. it doesn't work with Safari for some reason, it just sits there.
-If you "save as" the project drawer (think file mananger in DW) no longer shows the older, original file. you have to rescan the project before it shows up. nothing huge, but annoying.

not to totally derail this into a discussion just about Textmate, but if some more experienced users (Scott?) have any insight on these issues, i'd appreciate it. i've submitted these problems to the support mailing list, and it really didn't get resolved.

Offline

 

#16 2007-05-30 12:56 pm

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Batch process HTML files?

chipper wrote:

I am not an ubergeek coder type - i mainly just do front-end HTML/CSS. I probably leave 95% of textmate's abilities untouched. but for what I do need, it's great, albeit a little rough around the edges. the thing that i really like, and the reason i use it instead of textwrangler or other editors, is bundles. bundles are commands that you can put together and assign your own key command for them. that's just huge for me. for instance, i set up some simple commands that insert the proper HTML code for special typographic pieces - like real quote marks (and not tick marks).

Ditto.  The level of customization is really what makes it for me.  If I create a new CSS file and type cssbase+TAB, it generates it inserts the following:

Code:

/*
    scott hill
    wandermind.com

*/


/* @group StyleReset */
body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td { 
    margin:0;
    padding:0;
}
table {
    border-collapse:collapse;
    border-spacing:0;
    border:0;
}
fieldset,img { 
    border:0;
}
address,caption,cite,code,dfn,em,strong,th,var {
    font-style:normal;
    font-weight:normal;
}
ol,ul {
    list-style:none;
}
caption,th {
    text-align:left;
}
h1,h2,h3,h4,h5,h6 {
    font-size:100%;
    font-weight:normal;
}
q:before,q:after {
    content:'';
}
abbr,acronym { border:0;
}
br.clear{
    clear:both;
}
/* @end */


/* @group CommonElements */

body, table, input, select, option, li, td, th, table, tr, label{
    color: #333;
    font: 11px "Lucida Grande", Helvetica, Arial, sans-serif;
}

body{
    background:#fff url(images/background.png) repeat-x;
}
a{}
a:hover{}
p{}
h1{}
h2{}
h3{}
h4{}
h5{}
/* @end */

/* @group MainStructure */
#wrapper{}
#header{}
#content{}
#inner-content{}
#footer{}
/* @end */


/* @group Navigation */
#navigation{}
#navigation ul{}
#navigation ul li{}
#navigation ul li a{}
#navigation ul li a:hover{}
#navigation ul li a span{}
/* @end */

/* @group Forms */
form{}
fieldset{}
legend{}    
/* @end */


/* @group Pages */
/* @group Home */

/* @end */
/* @group About */

/* @end */
/* @group Contact */

/* @end */


/* @end */

or if I type bug+TAB it inserts:

Code:

echo "<pre>"; print_r(); echo "</pre>";

with the cursor in the parens.
And so on.  I have tons. Anything I type more than a couple of times in a project, I make a macro.  And the macros support scripting.  I have a few with regex in them to clean things up.

chipper wrote:

i also enjoy being able to modify the screen/text colors to my liking. superficial, but important to me.

Hardly superficial.  If you spend all day in an application, you want want to be able to tailor you're experience as much a possible.  Just like if you work at a desk all day, you want a comfortable chair.  It is important to me as well.

chipper wrote:

-Find in Project is still wonky - sometimes it adds code bits from other searches for no discernible reason

Don't have a problem with it, but would like the ability to have prefs for project to exclude folders/files.  In rails, I get all the test files and cache files.

chipper wrote:

-There is a bundle command to open the current document in a running browser. it doesn't work with Safari for some reason, it just sits there.

The one under HTML works for me.  It doesn't switch you to Safari though, but it opens the doc in it.  Also CMD+R in will refresh the front window in Safari.  Works for html, but also for external .js or .css files.  So you can be working on a .js/.css file and not have to swtich to safari and refresh, just CMD+R and you are good.

chipper wrote:

-If you "save as" the project drawer (think file mananger in DW) no longer shows the older, original file. you have to rescan the project before it shows up. nothing huge, but annoying.

Yea, it is busted, has been for a while. No work around that I know of.  I just don't think it is high on their priority of bugs, it's annoying, but as you said, the little quirks aren't that big of a deal.   Hell, I consider finding an app that is 95% perfect a huge score.  They can't all be QuickSliver, can they?


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#17 2007-05-30 6:29 pm

registered_user
bulletproof
From: padding: zero-pixels;
Registered: 2000-12-19
Posts: 16026
Website

Re: Batch process HTML files?

Marge!  I just tripled my productivity!

Offline

 

#18 2007-05-30 7:39 pm

Scott
Zombie Gorilla
From: Oregon
Registered: 2002-12-07
Posts: 3446
Website

Re: Batch process HTML files?

Hmmm...  downside of the ability to COMPLETELY customize with shortcuts and things it the ability to smurf up the app.

Somehow, I assigned the 6 key to some random function that I cannot locate.  If I press the 6 key, TM will create a new next .txt document in the root of my current project with a filename of the word next to my keystroke.!?!?!?!?!

Sucks... I have to use the 6 sometimes. sad


http://www.greatgamesexperiment.com/images/logo_kit/468x60-Blue.gif

Offline

 

#19 2007-05-31 9:28 am

Gipetto
Yankee Doodle's noodle
Royal Wombat
From: People! Ahg!!
Registered: 2000-09-24
Posts: 9942
Website

Re: Batch process HTML files?

Code:

echo '<pre>'.print_r($var,true).'</pre>';

For what its worth... I have this as a function in a base class so I always have quick access to $this->printPre($var);

Not that it has anything to do with TextMate, but I don't use TM for PHP. Its code completion and function hinting are nothing compared to Zend Studio.

And, just a quick addition. I wrote a bash script to update bundles from SVN since the GetBundles bundle updater seems to screw up and not notice some bundles that it has installed even though TM does.

Code:

#! /bin/bash
# Script for updating TextMate bundles from SVN
# @author Shawn Parker
# @copyright none
#
# Written because the GetBundles bundle never seems to work right, no offense to its author...
# this follows suggestions made on the TextMate wiki for how to pull from the TextMate SVN
# http://macromates.com/textmate/manual/bundles#getting_more_bundles

# define some base vars
AS_TEXTMATE_DIR='/Library/Application Support/TextMate';
BUNDLE_DIR='Bundles';
SUPPORT_DIR='Support';
SVN_URL='http://macromates.com/svn/Bundles/trunk';
BUNDLE_EXT='.tmbundle';

# set LC_TYPE to avoid encoding issues
export LC_CTYPE=en_US.UTF-8;

# make sure we have our bundles svn directory
if ! [ -d "$AS_TEXTMATE_DIR/$BUNDLE_DIR" ]
    then
        if ! [ -d "$AS_TEXTMATE_DIR" ]
            then
                mkdir "$AS_TEXTMATE_DIR";
        fi
                
    mkdir "$AS_TEXTMATE_DIR/$BUNDLE_DIR";
fi

# make sure an action is defined
if ! [ $1 ]
    then
        echo '';
        echo 'Missing action. Options are [install | list | update]';
        echo 'usage: ./tmbundle.sh [install] [package.tmbundle]';
        echo '       ./tmbundle.sh [list|update]';
        echo '';
        echo 'note: encapsulate long names with spaces in quotes';
        echo '      ./tmbundle.sh install "name with spaces.tmbundle"';
        echo '';
        exit 1;
fi

# figure out our action
if [ $1 = 'install' ]
    then
        # make sure we have our 2nd variable
        if ! [ "$2" ]
            then
                echo '';
                echo 'You must supply a bundle name to fetch for installs';
                echo 'usage: ./tmbundle [install] [package.tmbundle]';
                echo '';
                exit 2;
        fi
        
        # make sure we have a .tmbundle extention
        if ! [ "${2##*.}" = 'tmbundle' ]
            then
                echo '';
                echo 'invalid file extension or no file extension found';
                echo "trying $2$BUNDLE_EXT";
                BUNDLE="$2$BUNDLE_EXT";
        else
                BUNDLE=$2;
        fi
        
        ACTION="co";
        SOURCE="$SVN_URL/$BUNDLE_DIR/$BUNDLE";
        DEST="$AS_TEXTMATE_DIR/$BUNDLE_DIR/$BUNDLE";
        
elif [ $1 = 'list' ]
    then 
        ACTION="list";
        SOURCE="$SVN_URL/$BUNDLE_DIR";
        DEST="";
elif [ $1 = 'update' ]
    then
        ACTION="up";
        SOURCE="$SVN_URL/$BUNDLE_DIR/*$BUNDLE_EXT";
        DEST="$AS_TEXTMATE_DIR/$BUNDLE_DIR";
fi

svn $ACTION "$SOURCE" "$DEST";

# make sure we have an up to date support folder
if [ $1 = 'install' ] || [ $1 = 'update' ]
    then
        echo 'Updating Support Folder:';
        svn co "$SVN_URL/$SUPPORT_DIR" "$AS_TEXTMATE_DIR/$SUPPORT_DIR";
fi

# if we made it this far, exit (somewhat) gracefully
echo '';
echo 'SVN action complete';
echo '';

so, for example:
./tmbundle.sh list will list all available bundles in svn
./tmbundle install HTML.tmbundle will install HTML from svn
./tmbundle update will update all installed bundles from svn - it will only update bundles installed via svn. This will leave default bundles in TM alone.

This only accepts one bundle at a time. I haven't taken the time to learn how to efficiently overload bash functions yet.

I'm pretty sure its not broken... but I offer no warranty. It could probably be attached to an automator action very easily if anyone wants to go to the trouble.

Last edited by Gipetto (2007-05-31 9:35 am)

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson