Consecutive Find & Replace
Moderators: Dorian (MJT support), JRL
Consecutive Find & Replace
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
Thanks in advance...
Ronen
Two options
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
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
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
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
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
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.
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?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
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).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.
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...
run from top when in editor
Hi Ronen,
Example: StringReplace>theFileData,CRLF,:,theFileData
Gale
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.But I can't seem to get the code to work. It returns a file with contents: theFileData (just that word, nothing more).
Only if you do not want the search/replace to replace strings outside the {}.Is there any need to place complex search and/or replace strings in {}, for example?
Yes.Can I use CRLF as a search and/or replace parameter?
Example: StringReplace>theFileData,CRLF,:,theFileData
Gale
Re: run from top when in editor
Hi, Gale. Thanks again for the reply.gdyvig wrote:Hi Ronen,
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).
Gale
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...
PS. Just ran it again and got ##NO FILE## for the contents of 30_2.html
Ran exact same script twice?
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
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
Re: run from top when in editor
Hi, Gale.gdyvig wrote:Hi Ronen,
Can I use CRLF as a search and/or replace parameter?
Yes.
Example: StringReplace>theFileData,CRLF,:,theFileData
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.
StringReplace with CRLF
Do you mean like this?
Code: Select all
StringReplace>theFileData,><,>CRLF<,theFileData
Re: StringReplace with CRLF
>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.
Thanks again...
Ronen
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.
Thanks again...
Ronen
Try percent signs to enclose CRLF
Try this:
Gale
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
Last edited by gdyvig on Wed Jul 15, 2009 2:58 pm, edited 2 times in total.