Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

FindChangeByList script

New Here ,
Apr 30, 2009 Apr 30, 2009

I'm trying to use this pre-made script in CS4, and I customized the accompanying .txt file with all our Find-and Replace needs, but when I actually try to the run the script on a document, the following error message comes up:

Error Number: 23

Error String: does not have a value

File: [name and location of jsx file follows]

Line: 159

Source: app.doScript(myString, ScriptLanguage.javascript);

Anyone know how to get past this? It's very hard to see what Line 159 in the script file has to do with anything.

Thanks.

TOPICS
Scripting
29.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 25, 2009 Sep 25, 2009

Don't you launch the script first before loading up the find/change windows? I think it records what you enter

I think, it's been a few months

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 26, 2009 Sep 26, 2009

@Michael: I think you have to actually perform the complete Find/Change before you run the script. It seems you only entered your search options and then ran the script. Try what happens if you enter the Find/Change options, perform the search and then run the script. (I don't remember exactly how it works because I use 'the other' script: I only tried this one a few times and it didn't work well for my situation.)

@tynan: You are talking about the FindChangeByList script (which I also use, everyday btw!!!). Michael uses the RecordFindChange script (which entered this topic in post 38). That one DOES work with GREP but it works in a complete different way. So don't bother checking it out on monday...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 26, 2009 Sep 26, 2009

Tynan and J van E-

Thanks to both you for the quick responses! I'll try it after running a

Find/Change first chance I get.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 27, 2009 Sep 27, 2009

Success! I tried this on my machine at home and it captures find/change

settings without running the find/change first. My work machine might be

crippled by permissions problems. The corporate IT policy where I work is to

make virtually every folder "Read Only."

This is an awesome script that will help me a ton! I'll definitely write

about it on InDesignSecrets.com. Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 27, 2009 Sep 27, 2009

Yay

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 28, 2009 Sep 28, 2009

Even better, it now works on my work machine, thanks to one of my scripting

savvy co-workers.

He changed line 89 from

var myFile = new File( 'findChangeStrings.txt' );

to

var myFile = new File( '~/Desktop/findChangeStrings.txt' );

Not sure why specifying the path makes the difference, but it does.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 17, 2019 Jun 17, 2019

I know this is an old thread, but I am looking for Kasyans GREP Query script and unfortunately your site is down so perhaps you can help me by sending your script? Thanks in advance, Peter

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Jun 17, 2019 Jun 17, 2019

Peter,

You should be able to access the script from here.......Find change by queries  or copy it from below.

#targetengine "session"

CreatePalette();

function CreatePalette() {

    var myDialog = new Window('palette', 'Search-Replace by Queries');

    if (app.extractLabel("KasQueryGetDialogLocation") != "") {

        myDialog.location = app.extractLabel("KasQueryGetDialogLocation").split(",");

    }

    var myGroup = myDialog.add('group', undefined, '');

    myGroup.orientation = 'row';

    var myCreateQ = myGroup.add('button', undefined, 'Create Query', {name:'CreateQ'});

    var mySaveQ = myGroup.add('button', undefined, 'Save Query', {name:'mySaveQ'});

    var myRunQ = myGroup.add('button', undefined, 'Run Queries', {name:'myRunQ'});

    myDialog.show();

   

    myCreateQ.onClick = function() {

        app.changeTextPreferences = app.findTextPreferences = NothingEnum.nothing;

        app.menuActions.item("Find/Change...").invoke();

    }

    mySaveQ.onClick = function() {

        app.activeDocument.undo();

        var myDescription = GetDescription();

        var myQuery = {};

        myQuery.findTextPreferences = app.findTextPreferences.properties;

        myQuery.changeTextPreferences = app.changeTextPreferences.properties;

        myQuery.findChangeTextOptions = app.findChangeTextOptions.properties;

        myQuery.description = myDescription

        var mySerSettings = myQuery.toSource();

        var myFolderPath = Folder.decode(app.filePath.absoluteURI) + "/Scripts/Scripts Panel/Queries";

        var myFolder = Folder(myFolderPath);   

        if (!myFolder.exists) myFolder.create();

        //+++++++++++++++++++++++++++++++++++++++++++++

        var myNum = [];

        var aFile;

        var num;

        var myFiles = myFolder.getFiles("*.txt");

        for (i = 0; i < myFiles.length; i++) {

            aFile = myFiles.displayName;

            num = parseInt(aFile.split("_")[0]);

            myNum.push(num);

        }

        var myLastNumber = FindLastNumber(myNum);

        var myNumber = myLastNumber+1;

        if (isNaN (myNumber)) myNumber = 1;

        var myPrefix = (myNumber < 10) ? ("0" + myNumber) : myNumber;

        var myFileName = myPrefix + "_" + myDescription.substr(0, 30) + ".txt";

        var myPath = myFolderPath + "/" + myFileName;

        WriteToFile(mySerSettings, myPath);

        if (File(myPath).exists) {

            alert("Query has been created.");

        }

        else {

            alert("Something went wrong.");   

        }

    } // END mySaveQ.onClick

    myRunQ.onClick = function() {

        var myDoc = app.activeDocument;

        var myFolder = Folder (Folder.decode(app.filePath.absoluteURI) + "/Scripts/Scripts Panel/Queries");

        var myFiles = myFolder.getFiles("*.txt");

        for (i = 0; i < myFiles.length; i++) {

            var myFile = myFiles;

            var mySettings = eval(ReadFile(myFile));

           

            if (mySettings.changeTextPreferences.appliedCharacterStyle != "") {

                var myCharStyle = myDoc.characterStyles.itemByName(mySettings.changeTextPreferences.appliedCharacterStyle);

                if (!IsValidReference(myCharStyle)) {

                    WriteError( "Error -- " + GetDate()

                    + "\rQuery: " + myFile.displayName

                    + "\rFile: " + myDoc.name

                    +  "\rCharacter Style \"" + mySettings.changeTextPreferences.appliedCharacterStyle

                    + "\" doesn't exist\r------------------------------------------------\r" );

                    continue;

                }

            }

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

            app.findTextPreferences.properties = mySettings.findTextPreferences;

            app.changeTextPreferences.properties = mySettings.changeTextPreferences;

            app.findChangeTextOptions.properties = mySettings.findChangeTextOptions;

           

            try {

                myDoc.changeText();

            }

            catch(err) {

                WriteError( "Error -- " + GetDate()

                + "\rFile: " +myFile.displayName + " -- " + err.message + "\r");

            }

        }

    } // END myRunQ.onClick

    myDialog.onClose  = function() {

        app.insertLabel("KasQueryGetDialogLocation", String(myDialog.location));

    }

} // END CreatePalette

function WriteToFile(myText, myPath) {

    myFile = new File(myPath);

    myFile.open("w");

    myFile.write(myText);

    myFile.close();

}

function ReadFile(myFile) {

    myFile.open("r");

    var myText = myFile.read();

    myFile.close();

    return myText;

}

function GetDescription() {

    var myDialog = new Window("dialog", "Enter Description");

    var btnPanel = myDialog.add("panel", undefined, "Enter a short description of the search-replace operation");

    var editText = btnPanel.add("edittext");

    editText.preferredSize = [360, 40];

    editText.active = true;

    var myGroup = myDialog.add("group");

    myGroup.orientation = "row";

    var okBtn = myGroup.add("button", undefined, "OK");

    var cancelBtn = myGroup.add("button", undefined, "Cancel");

    var stText = btnPanel.add("statictext", undefined, "Don't use illegal characters: ? [ ] / \ = + < > : ; \" , * |");

    var res = myDialog.show();

    if (res == 1) {

        if (editText.text == "") {

            var myDescription = "unnamed";

        }

        else {

            var myDescription = editText.text;

        }

        return myDescription;

    }

    else {

        exit();

    }

}

//--------------------------------------------------------------------------------------------------------------

function WriteError(myText) {

    myFile = new File("~/Desktop/Error Report.txt");

    if ( myFile.exists ) {

        myFile.open("e");

        myFile.seek(0, 2);

    }

    else {

        myFile.open("w");

    }

    myFile.write(myText);

    myFile.close();

}

//--------------------------------------------------------------------------------------------------------------

function IsValidReference(ref) {

    try {

        ref.name;

        return true;

    }

    catch (myError) {

        return false;

    }

}

//--------------------------------------------------------------------------------------------------------------

function GetDate() {

    var myDate = new Date();

    if ((myDate.getYear() - 100) < 10) {

        var myYear = "0" + new String((myDate.getYear() - 100));

    } else {

        var myYear = new String ((myDate.getYear() - 100));

    }

    var myDateString = (myDate.getMonth() + 1) + "/" + myDate.getDate() + "/" + myYear + " " + myDate.getHours() + ":" + myDate.getMinutes() + ":" + myDate.getSeconds();

    return myDateString;

}

//--------------------------------------------------------------------------------------------------------------

function FindLastNumber(myArr) {

    var myLastNumber = myArr[0];

    for (i = 1; i < myArr.length; i++) {

        if (myArr > myLastNumber) {

            myLastNumber = myArr;

        }

    }

    return myLastNumber;

}

Regards,

Mike

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 18, 2019 Jun 18, 2019
LATEST

Thanks a ton Mike!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 02, 2009 Jul 02, 2009

not working ...

I've tried with the exact cs4 and the txt file you attached but it finds nothing, not even the simplest 'www.tynan.com' type text

Everthing else works lovely but this one search, what can I be doing differently?

So close and so far, this is starting to really hack me off

time to start trying on other macs here I suppose

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Jul 02, 2009 Jul 02, 2009

Did you run the CS3 version of the script before that? I noticed that CS3 version often spoils things with GREP search-replace. Try to restart ID and run only the CS4 version again.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 02, 2009 Jul 02, 2009

yes I did and I should have known thaI'm very very busy and a bit frazzled

I'll try that right nowI

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 02, 2009 Jul 02, 2009

Winner!

It works following the restart

Thank-you so much, this will save us so much time here!

Thanks for sticking with it and your prompt attention.

That's three bits of your scripting I'm using routinely now to process hundreds of books each with 50 seperate chapters, I can;t imagine doing ti any other way

Thanks again

Tynan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 16, 2009 Oct 16, 2009

Hi,

I'm have a problem using FindChangeByList (CS4, javascript) to apply paragraph styles in CS4.

My paragraph styles are nested into subfolders, so I can't figure out how to punctuate the stylenames. This line works if I apply a paragraph style that's not in a folder - but when I try to use one that's in a folder, it doesn't. The paragraph style is named "Endnotes Head" and it's in a folder named "2 Text 8.5 pt)"

I generated the query line using  RecordFindChange_CS3_Kas script. A huge timesaver - thanks! But, is there perhaps a different CS4 version that knows the syntax for style sheets within folders?

Here's the line that comes from RecordFindChange:


text    {findWhat:"(Endnotes)"}    {changeTo:"Endnotes", appliedParagraphStyle:"Endnotes Head", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true, wholeWord:false, caseSensitive:false}    //Comment

I tried using this syntax, but it didn't help:

text    {findWhat:"(Endnotes)"}    {changeTo:"Endnotes", appliedParagraphStyle:"Endnotes Head (2 Text 8.5 pt)", changeConditionsMode:1919250519}    {includeLockedStoriesForFind:false, includeLockedLayersForFind:false, includeHiddenLayers:false, includeMasterPages:false, includeFootnotes:true, wholeWord:false, caseSensitive:false}    //Comment

Does anyone know how to make this work? Is there a list somewhere of all this syntax?

I also tried generating queries using Kaysan's FindChangeByQueries3, but it didn't capture the formatting changes. Also, it processed the whole document without asking if I wanted that or just the story.

I really love the idea of using FindChangebyQueries - if it will do GREP and apply style sheets, I'd pay for the ability to mix and match stored find/change queries.

Thanks a million for any help you can offer!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 16, 2009 Oct 16, 2009

I am writing an interactive reference: http://www.kasyan.ho.com.ua/find_change_by_list1.html

But in is not tested and not finished. Click Paragraph Style area on the picture to see the parameters. I can't test it right now — terribly busy — I'll do it a little later.

Kasyan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 16, 2009 Oct 16, 2009

Thanks - I saw the dialog, but it didn't have a Paragraph Styles option in the list.

Please don't rush on my account - I'm extremely grateful for the tools you've already created!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 16, 2009 Oct 16, 2009

Just click on the area you are interested in — e.g.: Paragraph Styles: Address

then a yellow box will appear, from which you can copy an example for the parameters.

{appliedParagraphStyle:app.activeDocument.paragraphStyleGroups.item("Headings").paragraphStyles.item("Sub Heading")} for a style in a group

But I am warning again — it's not tested yet.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 16, 2009 Oct 16, 2009

I tested the syntax and it works:

appliedParagraphStyle:app.activeDocument.paragraphStyleGroups.item("Style Group 1"). paragraphStyles.item("Endnotes Head")

just write the name of your style group instead of "Style Group 1"

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 16, 2009 Oct 16, 2009

Kaysan--

Works GREAT! Thanks so much!

FYI, here's one of the things I can now use this for:

One of my publishing clients has editors who apply paragraph styles in Word. (They're learning InCopy, but not there yet). When I place the Word files, using Style Mapping to match up the paragraph and char styles in InDesign, they all come in with a) the styles "plussed out" (i.e. in Times New Roman, etc.) and also they all have one of my lesser-used character styles (8 condensed) applied to the entire story.  So, I can now use  the script to change all character style "8 condensed" to None, apply italic character styles to italicized text, and then reapply all of the paragraph styles.

I figured out a while ago that using Find-Change to reapply a paragraph style is like option-clicking—it strips local formatting (but not char styles). So, this is a quick way to clean out all those plussed-out styles.

Probably not the right forum, but do others have problems with placed text picking up unwanted character styles? Is there a way to avoid it?

Thanks again!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 16, 2009 Oct 16, 2009

I know about tree scripts that solve this problem:

At the bottom of this page you can find Preserve Local Formatting script by Dave Saundershttp://indesignsecrets.com/resources/plug-ins-and-scripts

This one is written by Jongwarehttp://www.jongware.com/binaries/preptext.zip

And here is my script — called Protect local styling — it was made on the basis of Dave's script. It works perfectly for our department, but it's specific for our workflow. http://www.kasyan.ho.com.ua/my_scripts.html

The main idea behind all these scripts is to save all formatting: bold, italic, etc. as character styles.

And to use InCopy is a very good idea — we work at least 3 times quicker since we started using it.

Kasyan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 18, 2009 Oct 18, 2009

That Preserve Local Formatting-script looks interesting, but it doesn't seem to do anything in ID CS4...? Preptext seems to work okay, but I'd like to try the other one too, to see which one is better. (Protect local styling only gives me a Russian warning... )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Oct 19, 2009 Oct 19, 2009

I can't check the Preserve Local Formatting script on CS4 until Wednesday, because I have CS4 only at work (I am a rare guest there). Try to place the script into "\Adobe InDesign CS3\Scripts\Scripts Panel\Version 4.0 Scripts" folder.

Protect local styling script is done specially for our workflow — it can't be used as is. It should be remade to your own needs — replace warnings, style names, find-replace strings, etc. with ones you want.

Kasyan

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Oct 19, 2009 Oct 19, 2009

Thanks for the reply. It still doesn't work when placed in 'Version 4.0 Scripts'. All I get is a dialogue saying 'Process the whole document?' (when I have nothing selected), but after that nothing happens. The other script does work better, but it skips (for instance) hyperlinks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 16, 2009 Oct 16, 2009

Thanks for keeping me posted. I got around my find only the first time issue by making unique placeholders in my document - so that each find string would only be found once. Automated the production of the text file using a Macro in Excel to find the data in a worksheet and write the find and change strings one line at a time.

Kathe Todd

Audio Editions

kathe-t@audioeditions.com

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 22, 2009 Nov 22, 2009

Kasyan, first of all, thanks so much for that Record script, it has really helped me to understand alot of how the java functions in that find/change file. I had one question about it though, at the company i work for, I'm currently overhauling all of their style sheets, and using the findchangebylist script to convert all the defunct styles to new styles. the problem is that if the old styles aren't left in the document, i get an error message and the script screeches to a halt. Is there a way for this script to ignore any styles that it doesn't find matches for in the document so i don't have to leave a gargantuan list of old styles in my styles panel?

Also, looking for a way in GREP to strip all local formatting that doesn't come from style sheets to add into my list. Is there a menu option in GREP for that so i don't have to make it strip bold, then italic, then superior, then caps, etc?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines