Consecutive Find & Replace

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Consecutive Find & Replace

Post by GalaxyMan » Sun Jul 12, 2009 10:49 am

I am trying to clean up HTML code in Dreamweaver using Find & Replace. I need to do approximately 10-20 different Find & Replace actions. How can I get Macro Scheduler to wait until Dreamweaver has finished running the current Find & Replace action before the next one starts?

Thanks in advance...

Ronen

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Two options

Post by gdyvig » Sun Jul 12, 2009 2:45 pm

Hi Ronen,

If DreamWeaver code can be modified with external editors you can use Macro Scheduler's StringReplace command.

If you must use the DreamWeaver editor you need a smart wait that detects when the Replace String has finished. One way is the WaitWindowChanged command.

If that does not work, look at how DreamWeaver signals you that it is finished with the Replace String.

Maybe a status message. Do a WaitScreenImage for that message.


Or the Replace String label changes in appearance. If the label is a light color when disabled and dark when enabled, do a WaitScreenImage for the enabled label.

Gale

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Sun Jul 12, 2009 2:48 pm

Hi, Gale.

Very nice idea. I'll play with it and let you know. It's probably going to have to be a WaitScreenImage for a status message...

Thanks again...

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Sun Jul 12, 2009 4:02 pm

I'm with Gale. Dreamweaver's output will be plain text files, even if they have some other suffix, html, css, php etc. MacroScheduler can do this for you directly.

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Mon Jul 13, 2009 6:57 am

Okay, I've attempted to incorporate the suggestions, but I can't seem to get it to move to the 'next Clean-Up macro'.

Here is the code I'm trying to use...

SetFocus>Dreamweaver*

//Open Find & Replace dialog
Press CTRL
Send>f
WaitWindowOpen>Find and Replace
Release CTRL

//Fill in Fine & Replace dialog >
HELP
.2
Press Tab
Wait>0.2
Send>DO NOT ASSIST

//Apply Find & Replace
Wait>.2
Press ALT
Send>a
WaitWindowOpen>Adobe Dreamweaver CS4
Release ALT

//Finding the photo label
WaitScreenImage>D:\done.bmp,20
Let>PhotoLabel=D:\done.bmp
FindImagePos>D:\done.bmp,SCREEN,20,1,X,Y,NumFound

If>numFound>0

//Run next Clean-Up macro

//Open Find & Replace dialog
Press CTRL
Send>f
Release CTRL
WaitWindowOpen>Find and Replace

//Fill in Find & Replace dialog TABLE
Send>TABLE
Wait>.2
Press Tab
Send>CHAIRS

//Apply Find & Replace
Wait>.2
Press ALT
Send>a
Release ALT
WaitWindowOpen>Adobe Dreamweaver CS4

Endif

Thanks again.....

Ronen

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Jul 13, 2009 9:52 am

I think you're making this hard for yourself. As others have noted, Dreamweaver simply edits plain ascii text files. So why not just do this:

ReadFile>c:\webfiles\index.html,theFileData
StringReplace>theFileData,HELP,DO NOT ASSIST,theFileData
DeleteFile>c:\webfiles\index.html
Let>WLN_NOCRLF=1
WriteLn>c:\webfiles\index.html,res,theFileData

I hope you can see what this does. The first line reads the contents of the file into a variable called theFileData. The second line replaces all occurences of "HELP" in the file string with "DO NOT ASSIST". The next line deletes the original file. The last two write the modified data back to the original filename again.

You could if you prefer write to a new file to retain the original and remove the DeleteFile line.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Tue Jul 14, 2009 5:24 pm

mtettmar wrote:I think you're making this hard for yourself. As others have noted, Dreamweaver simply edits plain ascii text files. So why not just do this:

ReadFile>c:\webfiles\index.html,theFileData
StringReplace>theFileData,HELP,DO NOT ASSIST,theFileData
DeleteFile>c:\webfiles\index.html
Let>WLN_NOCRLF=1
WriteLn>c:\webfiles\index.html,res,theFileData

I hope you can see what this does. The first line reads the contents of the file into a variable called theFileData. The second line replaces all occurences of "HELP" in the file string with "DO NOT ASSIST". The next line deletes the original file. The last two write the modified data back to the original filename again.

You could if you prefer write to a new file to retain the original and remove the DeleteFile line.
This makes much more sense, of course. But I can't seem to get the code to work. It returns a file with contents: theFileData (just that word, nothing more).

Have I done something wrong here? I didn't want to delete my original, so I remarked that line out and changed the destination file to a different name, which worked insofar as it was created.

ReadFile>d:\30.html,theFileData
StringReplace>theFileData,TR BGCOLOR="#0000ff",TR,theFileData
//DeleteFile>d:\30.html
Let>WLN_NOCRLF=1
WriteLn>d:\30_2.html,res,theFileData

A few more questions, if I may...

Is there any problem using full HTML tags in the StringReplace?

Is there any need to place complex search and/or replace strings in {}, for example?

Can I use CRLF as a search and/or replace parameter?

Thanks again...

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

run from top when in editor

Post by gdyvig » Tue Jul 14, 2009 10:34 pm

Hi Ronen,
But I can't seem to get the code to work. It returns a file with contents: theFileData (just that word, nothing more).
Your code looks correct, the most likely cause is that you ran the script from the editor somewhere after the 2nd line. This would cause theFileData to be interpretted as text.
But I can't seem to get the code to work. It returns a file with contents: theFileData (just that word, nothing more).
No problem using the HTML tags. Its just text.

Is there any need to place complex search and/or replace strings in {}, for example?
Only if you do not want the search/replace to replace strings outside the {}.
Can I use CRLF as a search and/or replace parameter?
Yes.
Example: StringReplace>theFileData,CRLF,:,theFileData


Gale

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Re: run from top when in editor

Post by GalaxyMan » Wed Jul 15, 2009 4:17 am

gdyvig wrote:Hi Ronen,
But I can't seem to get the code to work. It returns a file with contents: theFileData (just that word, nothing more).
Your code looks correct, the most likely cause is that you ran the script from the editor somewhere after the 2nd line. This would cause theFileData to be interpretted as text.

Gale
Hi, Gale. Thanks again for the reply.

I didn't run it from the editor, but from the main Macro Scheduler window, by clicking on Run Now. Shouldn't running it like that always run it from the beginning?

Very confused... :roll:

PS. Just ran it again and got ##NO FILE## for the contents of 30_2.html

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Ran exact same script twice?

Post by gdyvig » Wed Jul 15, 2009 5:25 am

The first time you ran the script the contents of the d:\30_2.html output file was "theFileData". That indicates the ReadFile never created a variable of that name.

One possibility is trailing spaces, if one existed the name of the variable created would be "theFileData ". To prevent this problem select the item from the Edit menu to delete trailing spaces.

Another possibility is the script could not read the file, for example if there is a permissions issue. I'm not sure if this is the symptom you see in this case.

The second time you ran the script the contents of the d:\30_2.html file was "##NOFILE##". That is the value ReadFile assigns to the output variable (thiFileData) when the file does not exist. Did you delete, move, or rename the file? Or change the file name in the script?

By the way, when I ran your script I did not run the ReadFile line. Instead I just used a Let> command to assign a value to theFileData and ran the rest of the script, which did exactly what you want. So the problem is in the ReadFile command or with the file itself.

Gale

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Post by GalaxyMan » Wed Jul 15, 2009 6:28 am

Hi, Gabe.

I write this with my head hanging in embarrassment. In the code I used the .html file extension, while in reality my file was .HTM. Jeesh!!!

Needless to say, it works magnificently now.

Live & Learn...

Many thanks once again,

Ronen

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Re: run from top when in editor

Post by GalaxyMan » Wed Jul 15, 2009 6:38 am

gdyvig wrote:Hi Ronen,

Can I use CRLF as a search and/or replace parameter?

Yes.
Example: StringReplace>theFileData,CRLF,:,theFileData

Gale
Hi, Gale.

I'm trying to replace the end bracket of an HTML tag followed immediately by the opening bracket of an HTML tag with the same but with the opening bracket on a new line.

[Closing Bracket][Opening Bracket]

replaced with

[Closing Bracket]
CRLF
[Opening Bracket]

How can I make the CRLF part of a complex search and/or replace expression?

PS. EDIT: I've described this in this way because I notice that sometimes the text function here doesn't render some things accurately that I try to input, like brackets and expressions in quotes. I see that I'm right.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

StringReplace with CRLF

Post by gdyvig » Wed Jul 15, 2009 9:36 am

Do you mean like this?

Code: Select all

StringReplace>theFileData,><,>CRLF<,theFileData 

User avatar
GalaxyMan
Junior Coder
Posts: 40
Joined: Sat Jun 27, 2009 7:21 pm

Re: StringReplace with CRLF

Post by GalaxyMan » Wed Jul 15, 2009 11:19 am

>CRLF< shows up, literally. It doesn't seem to recognize or execute the CRLF.

I've set up maybe 30 different StringReplace statements for this particular macro, to run consecutively, and this is the only one that doesn't seem to work, which wouldn't ruin my day in the great scheme of things. I can always open it in Dreamweaver and do it if need be. Already this is going to save me a huge amount of time for each need to use this macro. Some of these Find & Replace statements used to take almost 15-20 minutes for Dreamweaver to run, there were so many instances to act on, sometimes upwards of 4-5000. This macro runs ALL of my F&R changes faster than I can count to 2. You have no idea how happy that makes me. :D

Thanks again...

Ronen

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Try percent signs to enclose CRLF

Post by gdyvig » Wed Jul 15, 2009 1:25 pm

Try this:

Code: Select all

//The commented out command was written in error and quoted by Ronen.
//This is what happens when you forget to click the code button
//at the end of the code block.
//StringReplace>theFileData,><,>%CRLF%<theFileData>VAREXPLICIT=1.
StringReplace>theFileData,><,>%CRLF%<,theFileData
Gale
Last edited by gdyvig on Wed Jul 15, 2009 2:58 pm, edited 2 times in total.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts