0
[js] CS Scripting not working with CS3
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/td-p/1158193
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
Hello,
We had a JavaScript made for us that enabled the user to exchange certain text within a document.
This script works fine with CS (Ver.3.0.1) but gives a JavaScript Error - #55, Error String: Object does not support the property or method 'findPreferences' with CS3 (Ver.5.0)
I have tried 'tinkering' around with the scripting - but I have zero experience with JavaScript and have not found a solution.
Additionally the people that wrote the initial script are not available.
I have bought several books but they all seem like alien-language to me
:-(
Below is the section of origional CS scripting.
Can anyone point out to me WHY this script does not work with CS3?
And WHERE I should start looking - changing?
Thanks in advance for your help and guidence.
Lee
--------------------------
//-------------------------------------------------
// Exchange the text
//-------------------------------------------------
function actProjectData(oneDoc, oneResult){
app.findPreferences = null; app.changePreferences = null;
oneDoc.search(undefined, true, true, oneResult[0],{appliedCharacterStyle:oneDoc.characterStyles.item(myProjectTitleCharStyleName)}, undefined);
oneDoc.search(undefined, true, true, oneResult[1],{appliedCharacterStyle:oneDoc.characterStyles.item(myOfferNoCharStyleName)}, undefined);
oneDoc.search(undefined, true, true, oneResult[2],{appliedCharacterStyle:oneDoc.characterStyles.item(myOfferDateCharStyleName)}, undefined);
app.findPreferences = null; app.changePreferences = null;
}
We had a JavaScript made for us that enabled the user to exchange certain text within a document.
This script works fine with CS (Ver.3.0.1) but gives a JavaScript Error - #55, Error String: Object does not support the property or method 'findPreferences' with CS3 (Ver.5.0)
I have tried 'tinkering' around with the scripting - but I have zero experience with JavaScript and have not found a solution.
Additionally the people that wrote the initial script are not available.
I have bought several books but they all seem like alien-language to me
:-(
Below is the section of origional CS scripting.
Can anyone point out to me WHY this script does not work with CS3?
And WHERE I should start looking - changing?
Thanks in advance for your help and guidence.
Lee
--------------------------
//-------------------------------------------------
// Exchange the text
//-------------------------------------------------
function actProjectData(oneDoc, oneResult){
app.findPreferences = null; app.changePreferences = null;
oneDoc.search(undefined, true, true, oneResult[0],{appliedCharacterStyle:oneDoc.characterStyles.item(myProjectTitleCharStyleName)}, undefined);
oneDoc.search(undefined, true, true, oneResult[1],{appliedCharacterStyle:oneDoc.characterStyles.item(myOfferNoCharStyleName)}, undefined);
oneDoc.search(undefined, true, true, oneResult[2],{appliedCharacterStyle:oneDoc.characterStyles.item(myOfferDateCharStyleName)}, undefined);
app.findPreferences = null; app.changePreferences = null;
}
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158194#M338478
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
>Can anyone point out to me WHY this script does not work with CS3?
And WHERE I should start looking - changing?
Find and change have changed a lot in CS3 scripting. The first thing to change is this:
>app.findPreferences = null; app.changePreferences = null;
change to
>app.findTextPreferences = null; app.changeTextPreferences = null;
Then in the rest of the script, look for ".search(" and change the format of the search commands. They're not in the code that you posted, so look elsewhere.
Peter
And WHERE I should start looking - changing?
Find and change have changed a lot in CS3 scripting. The first thing to change is this:
>app.findPreferences = null; app.changePreferences = null;
change to
>app.findTextPreferences = null; app.changeTextPreferences = null;
Then in the rest of the script, look for ".search(" and change the format of the search commands. They're not in the code that you posted, so look elsewhere.
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158195#M338480
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
Thank you Peter,
the changing of app.findPreferences & app.changePreferences has eliminated the Error #55.
A small step for you - a giant leep for me!
:-)
I have looked around and 'played' with the ".search(" commands - but did not get any further.
I have tried using a debugger - but I simply get stopped at the first instance of ".search(" with a new JavaScript Error:
> Error Number: 24
Error String: oneDoc.search is not a function
Unfortunatly I am unable to include/attach the script - which makes this rather frustrating to explain.
I have uploaded here: http://www.freetimecorner.ch/joomla2/images/stories/pod_v1_1.txt
if you are interested in seeing the full picture.
Am I to assume that 'search' is an incorrect function?
If so - shouldn't it be something along the lines of 'FindChange...'?
the changing of app.findPreferences & app.changePreferences has eliminated the Error #55.
A small step for you - a giant leep for me!
:-)
I have looked around and 'played' with the ".search(" commands - but did not get any further.
I have tried using a debugger - but I simply get stopped at the first instance of ".search(" with a new JavaScript Error:
> Error Number: 24
Error String: oneDoc.search is not a function
Unfortunatly I am unable to include/attach the script - which makes this rather frustrating to explain.
I have uploaded here: http://www.freetimecorner.ch/joomla2/images/stories/pod_v1_1.txt
if you are interested in seeing the full picture.
Am I to assume that 'search' is an incorrect function?
If so - shouldn't it be something along the lines of 'FindChange...'?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158196#M338481
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
>Am I to assume that 'search' is an incorrect function?
That's right. In your script you may have someting like this:
>oneDoc.search ("a", true, false, "b")
but search() doesn't exist anymore. In CS3, you need this:
to replace "a" with "b". "true" and "false" set case-sensitivity and whole-word matches, which is done differently in CS3:
Peter
That's right. In your script you may have someting like this:
>oneDoc.search ("a", true, false, "b")
but search() doesn't exist anymore. In CS3, you need this:
app.findTextPreferences.findWhat = "a";
app.changeTextPreferences.changeTo = "b";
oneDoc.changeText();
to replace "a" with "b". "true" and "false" set case-sensitivity and whole-word matches, which is done differently in CS3:
app.findChangeTextOptions.wholeWord = true; // or false
app.findChangeTextOptions.caseSensitive = true; // or false
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158197#M338482
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
Come to think of it, maybe it's easier to create a folder "Version 4.0 Scripts" under your scripts folder and place your CS script in there. Maybe that will do the trick. Should have thought of that earlier.
Peter
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158198#M338483
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
> Come to think of it, maybe it's easier to create a folder "Version 4.0 Scripts" under your scripts folder and place your CS script in there. Maybe that will do the trick. Should have thought of that earlier.
Tried this, but it didn't seem to do anything... But certainly a 'try' worth.
Currently playing around with the:
> app.findTextPreferences.findWhat = "a";
app.changeTextPreferences.changeTo = "b";
oneDoc.changeText();
I've got to the point where I have no error messages 🙂 Now I'm really flying.....
Fact is - not all text and also the wrong text is replaced!!!
I'm currently playing with the script to try and replace all texts with a given paragraph style with the entered text...
Not proving to be simple for me, but I'm learning rather a lot!
Now that doesn't sound very clear when I go back and read it!
What I want to say is:
Each page of the document has the project name, No & Date on it (each having their own paragraph style)
so
With this script it asks you the Project name, No. and Date and then goes through the whole document and replaces all instants of those texts with specific paragraph styles with the newly 'entered' text.
Proving to be a little mountain for me - Thought it would only be a hill!
Tried this, but it didn't seem to do anything... But certainly a 'try' worth.
Currently playing around with the:
> app.findTextPreferences.findWhat = "a";
app.changeTextPreferences.changeTo = "b";
oneDoc.changeText();
I've got to the point where I have no error messages 🙂 Now I'm really flying.....
Fact is - not all text and also the wrong text is replaced!!!
I'm currently playing with the script to try and replace all texts with a given paragraph style with the entered text...
Not proving to be simple for me, but I'm learning rather a lot!
Now that doesn't sound very clear when I go back and read it!
What I want to say is:
Each page of the document has the project name, No & Date on it (each having their own paragraph style)
so
With this script it asks you the Project name, No. and Date and then goes through the whole document and replaces all instants of those texts with specific paragraph styles with the newly 'entered' text.
Proving to be a little mountain for me - Thought it would only be a hill!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158199#M338484
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
To look in a particular paragraph style, add this line:
Peter
app.findTextPreferences.findWhat = "a";
app.findTextPreferences.appliedParagraphStyle = "xxxx";
app.changeTextPreferences.changeTo = "b";
oneDoc.changeText();
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158200#M338485
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
🙂
So now I'm coming down the mountain....
Peter - you saved me from pulling my last few hairs out!
Just one little snag - It does not change the text that is locked into the page!
I have to release (Shift+Ctrl) the text element before it will 'see' and 'change' the contents of those too!
Is there a way that the 'find' function will also look into fixed text elements?
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158201#M338486
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
Hi Lee,
I'm not sure at all if it woud work, but try this:
http://www.businessweekly.h.com.ua/downloads/Pod_v2_1.jsx
I don't have a scripting guide for CS in my archive too old version so don't have a clear idea of how your script works. Could you describe in more details what it does and it would be even better if you send me an example document.
Kasyan
I'm not sure at all if it woud work, but try this:
http://www.businessweekly.h.com.ua/downloads/Pod_v2_1.jsx
I don't have a scripting guide for CS in my archive too old version so don't have a clear idea of how your script works. Could you describe in more details what it does and it would be even better if you send me an example document.
Kasyan
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Valorous Hero
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158202#M338487
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
>It does not change the text that is locked into the page!
If you mean text on master page use:
app.findChangeTextOptions.includeMasterPages = true;
If you mean text on master page use:
app.findChangeTextOptions.includeMasterPages = true;
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158203#M338488
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
Lee,
Do you mean something on a master page? If yes, add this line:
>app.findChangeTextOptions.includeMasterPages = true;
anywhere before oneDoc.changeText();
Peter
Do you mean something on a master page? If yes, add this line:
>app.findChangeTextOptions.includeMasterPages = true;
anywhere before oneDoc.changeText();
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158204#M338489
Jun 04, 2008
Jun 04, 2008
Copy link to clipboard
Copied
I had tried the 'includeLockedLayersForFind' and 'includeLockedStoriesForFind' - but never thought about the master! Dooooh!
🙂 🙂 :-)
Peter - you have just become my hero!
Final section of scripting that's good for me:
----------------------------------------------------
app.findChangeTextOptions.includeMasterPages = true
app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
app.changeTextPreferences.changeTo = oneResult[0];
oneDoc.changeText();
app.findTextPreferences.appliedCharacterStyle = myOfferNoCharStyleName;
app.changeTextPreferences.changeTo = oneResult[1];
oneDoc.changeText();
app.findTextPreferences.appliedCharacterStyle =
myOfferDateCharStyleName;
app.changeTextPreferences.changeTo = oneResult[2];
oneDoc.changeText();
-------------------------------------------------------
If ever you are in Switzerland, near Zürich - let me know - I owe you a night of free beer!
Ladies and Gents....
I have just climb a mountain that has been stopping me from advancing for over a week!
Four hours talking with Peter and I'm now standing on the other side - as happy as a pig in muck!
🙂 🙂 :-)
Peter - you have just become my hero!
Final section of scripting that's good for me:
----------------------------------------------------
app.findChangeTextOptions.includeMasterPages = true
app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
app.changeTextPreferences.changeTo = oneResult[0];
oneDoc.changeText();
app.findTextPreferences.appliedCharacterStyle = myOfferNoCharStyleName;
app.changeTextPreferences.changeTo = oneResult[1];
oneDoc.changeText();
app.findTextPreferences.appliedCharacterStyle =
myOfferDateCharStyleName;
app.changeTextPreferences.changeTo = oneResult[2];
oneDoc.changeText();
-------------------------------------------------------
If ever you are in Switzerland, near Zürich - let me know - I owe you a night of free beer!
Ladies and Gents....
I have just climb a mountain that has been stopping me from advancing for over a week!
Four hours talking with Peter and I'm now standing on the other side - as happy as a pig in muck!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158205#M338490
Jun 05, 2008
Jun 05, 2008
Copy link to clipboard
Copied
Hello Peter - I do hope you are still around?
I am wanting to add a little addition to the script you help me with yesterday.
Once I have 'found' the text elements with the given character style, i.e.:
> app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
I then want to store its current content into a string before I then go and replace it, i.e.:
> app.changeTextPreferences.changeTo = oneResult[0];
oneDoc.changeText();
I have tried something along the lines of (please don't laugh):
> var myCurrentProjectTitle = (app.findTextPreferences.appliedCharacterStyle.content = myProjectTitleCharStyleName);
...but as you can guess, it doesn't work (for reasons I don't yet know why).
Are you still there to point me in the right direction?
It would be greatly appreciated!
Lee
I am wanting to add a little addition to the script you help me with yesterday.
Once I have 'found' the text elements with the given character style, i.e.:
> app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
I then want to store its current content into a string before I then go and replace it, i.e.:
> app.changeTextPreferences.changeTo = oneResult[0];
oneDoc.changeText();
I have tried something along the lines of (please don't laugh):
> var myCurrentProjectTitle = (app.findTextPreferences.appliedCharacterStyle.content = myProjectTitleCharStyleName);
...but as you can guess, it doesn't work (for reasons I don't yet know why).
Are you still there to point me in the right direction?
It would be greatly appreciated!
Lee
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158206#M338491
Jun 05, 2008
Jun 05, 2008
Copy link to clipboard
Copied
Try this:
To get to the contents of found items, you need to use findText(), not changeText(). When you say f = oneDoc.findText(), you get all occurrences of text that has the paragraph style applied to it. These are stored in array, here, f. The first object found is f[0], its contents is f[0].contents. This precedes your change action.
Is that what you were after?
Peter
app.findChangeTextOptions.includeMasterPages = true;
app.findTextPreferences.appliedCharacterStyle = myProjectTitleCharStyleName;
f = oneDoc.findText();
var myCurrentProjectTitle = f[0].contents;
To get to the contents of found items, you need to use findText(), not changeText(). When you say f = oneDoc.findText(), you get all occurrences of text that has the paragraph style applied to it. These are stored in array, here, f. The first object found is f[0], its contents is f[0].contents. This precedes your change action.
Is that what you were after?
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158207#M338492
Jun 05, 2008
Jun 05, 2008
Copy link to clipboard
Copied
🙂
Well, the night of beer has increased to two!
BTW - Can you recomend a good book for noobs like me?
I have bought both 'Sams Teach Yourself Java in 21 days' & 'Beginning Programming with Java for Dummies' - Both of which lost me once I got past the Index page ! ! !
Thanks a million.
Lee
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Community Expert
,
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158208#M338493
Jun 05, 2008
Jun 05, 2008
Copy link to clipboard
Copied
You can try the "Adobe guide to scripting": in the ESTK, Help > SDK. Another possibility is http://oreilly.com/catalog/9780596528171/ which is really for CS2 but covers a lot of CS3 as well. The introductory chapter shows how you can explore the object model, and that hasn't changed in principle, nor have the Javascript basics.
Peter
PS: Look forward to all that beer!
Peter
PS: Look forward to all that beer!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
_Lee_Fielding_
AUTHOR
New Here
,
LATEST
/t5/indesign-discussions/js-cs-scripting-not-working-with-cs3/m-p/1158209#M338494
Jun 05, 2008
Jun 05, 2008
Copy link to clipboard
Copied
Thanks for the tip...
Beer: No unfortunatly it's not like a good bitter or ale!
The beer around here isn't that good. Have to pop over to Germany for the better stuff!
But it still doesn't touch the likes of a chlled Tetley's with a pack of pork scratchings....
Thanks again.
Beer: No unfortunatly it's not like a good bitter or ale!
The beer around here isn't that good. Have to pop over to Germany for the better stuff!
But it still doesn't touch the likes of a chlled Tetley's with a pack of pork scratchings....
Thanks again.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

