Scripts – Linked Scripts

Search and Replace version 3.4+ has a special script operator that allows two or more scripts to be ‘chained’ in succession. The same effect is achieved in earlier versions by using .bat/.cmd files to launch sequential instances of the program, each instance to run a different script. The Script Link function in version 3.4 can be useful to those who are uncomfortable with .bat/.cmd files.

The syntax for linking scripts is modeled at the bottom of the script below. For version 3.4 you must create/edit scripts that contain Script Link instructions with your text editor. The version 3.4 internal Script Editor respects existing Script Link references but you cannot create them via the Script Editor.

Please read through this entire section before you use Script Linking for the first time!

Example Script with Script Link References

[Script for Search and Replace]
[Search /i]
something
[Replace]
something
[Path]
D:\TEST\somefile.txt
[End of Search and Replace Script]
D:\TEST\Script2.srs
D:\TEST\Script3.srs
D:\TEST\Script4.srs
…(Additional scripts)…
D:\TEST\ScriptLast.srs

Script Link references are placed at the bottom of a script file, below the [End of Search and Replace Script] tag. The format is to specify the full path name to a script file.

Notes:

  • Linked scripts perform the same ‘search-only’ vs. ‘search/replace’ operation as that in effect for script that launches them. For example, if the initial script containing link references to other script(s) is launched as a search-only operation, the chained scripts will also perform a search-only. Conversely, if the initial script is launched as an search-replace, the other scripts will also perform a search-replace. See below for usage suggestions.

  • Linked Scripts are intended for scripts edited via an external editor and then launched from the command line (&/or .bat/.cmd files). Alternative, you can launch the initial script from the Favorites Menu. Scripts loaded into the Script Editor and then launched into the main Search and Replace program will also chain scripts if that script contains script link references. However, our intend use for linked scripts is via the command line or Favorites.

  • Avoid nested Linked Script references!! For example, if script1.srs chains to script2.srs, do not place any linked script references in script2.srs.

  • Individually debug all scripts in advance. There is no way to ‘pause’ a series of linked scripts.

  • Scripts can have a mixture of replace confirmations vs. not. However, be aware of the consequences to any later operations if you chose to skip a replace.

  • If you prefer to use the Script Editor for your editing chores, consider using ‘dummy scripts’ that would not need any editing to launch your linked scripts. See below for usage suggestions.

Usage Suggestions

Case 1 – Linking a mixture of Search-Only and Search-Replace operations

Create separate initial scripts for each type of operation. For example, if you wish to perform some replaces and then a search, chain your search-replace scripts and then separately launch your search-only script. A .bat command line for this might be

start /w c:\tools\sr\sr32.exe /r /c”c:\tools\sr\scripts\replaces.srs” /q
start /w c:\tools\sr\sr32.exe /s /c”c:\tools\sr\scripts\search.srs” /q

The script ‘c:\tools\sr\scripts\replaces.srs’ might can contain one or more links to other search-replace operation scripts. Do not make a mistake and put a script link reference to a script intended as a search-only script in ‘replaces.srs’ – the program will perform a replace instead because you launched that script via a search-replace.

Case 2 – Using ‘Launching’ Scripts’

You can use scripts that accomplish nothing meaningful as launching points for linking scripts. Let’s say you have a series of complex scripts the require debugging and you want to easily test these in sequence. Instead of specifying the linked script references in a main script, create one or more scripts whose sole purpose is to launch your main scripts.

Since all scripts must have some kind of valid operation, your ‘launching’ scripts must contain valid search-replace strings. However, you can use ‘dummy’ strings that would never be found in any file. Likewise, you can use a path/mask that refers to a file that does not exist on your drive.

Example:

[Script for Search and Replace]
[Search]
bbbbbbbbbb
[Replace]
bbbbbbbbbb
[Path]
D:\TEST\this_file_does_not_exist.txt
[End of Search and Replace Script]
D:\TEST\Script2.srs
D:\TEST\Script3.srs

The script above accomplishes nothing – even if the file, ‘this_file_does_not_exist.txt’,. is present on your drive, if launched as a search-replace, the operation itself changes nothing because the strings are identical.

Linked Scripts