[GastForen Programmierung/Entwicklung JavaScript Text Auswahl

  • Suche
  • Hilfe
  • Lesezeichen
  • Benutzerliste
Themen
Beiträge
Moderatoren
Letzter Beitrag

Text Auswahl

meziane
Beiträge gesamt: 3

21. Sep 2006, 17:11
Beitrag # 1 von 1
Bewertung:
(894 mal gelesen)
URL zum Beitrag
Beitrag als Lesezeichen
Hallo,
wie kann ich dieses Script ändern damit: 1. wenn das gesuchte Wort gefunden ist, erst augewählt wird und dann nach meiner Bestätigung ersetzt wird.

Danke
meziane


//TextCleanup.jsx
//An InDesign CS2 JavaScript
//
//Loads a series of tab-delimited strings from a text file, then performs a series
//of find/change operations based on the strings read from the file.
//
//The data file is tab-delimited, with carriage returns separating records.
//
//The format of each record in the file is:
//findProperties<tab>changeProperties<tab>range_string<tab>description
//
//Where:
//<tab> is a tab character
//findProperties is a properties record (as text)
//changeProperties is a properties record (as text)
//range_string is either "all" or "once"
//description is a description of the find/change operation
//
//Very simple example:
//{findText:" "} {changeText:" "} all Find all double spaces and replace with single spaces.
//
//More complex example:
//{findText:"^9^9.^9^9"} {appliedCharacterStyle:"price"} once Find $10.00 to $99.99 and apply the character style "price".
//
//All InDesign search metacharacters are allowed in the findText property; all but wildcards are allowed in the changeText property.
//
//For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting.html
//or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
//
var myObject;
var myCheckSelection = false;
if(app.documents.length != 0){
if(app.activeDocument.stories.length != 0){
if(app.selection.length != 0){
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
var myArray = myDisplayDialog();
myObject = myArray[0];
myCheckSelection = myArray[1];
break;
default:
myObject = app.activeDocument;
break;
}
}
else{
myObject = app.activeDocument;
}
if(myObject != "None"){
myTextCleanup(myObject, myCheckSelection);
}
}
else{
alert("The current document contains no text. Please open a document containing text and try again.");
}
}
else{
alert("No documents are open. Please open a document and try again.");
}
function myDisplayDialog(){
var myCheckSelection = false;
var myDialog = app.dialogs.add({name:"TextCleanup"});
with(myDialog.dialogColumns.add()){
with(dialogRows.add()){
with(dialogColumns.add()){
staticTexts.add({staticLabel:"Search Range"});
}
var myRangeButtons = radiobuttonGroups.add();
with(myRangeButtons){
radiobuttonControls.add({staticLabel:"Selected Story", checkedState:true});
radiobuttonControls.add({staticLabel:"Document"});
if(app.selection[0].contents != ""){
radiobuttonControls.add({staticLabel:"Selection"});
}
}
}
}
var myResult = myDialog.show();
if(myResult == true){
switch(myRangeButtons.selectedButton){
case 0:
switch(app.selection[0].constructor.name){
case "InsertionPoint":
case "Character":
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
myObject = app.selection[0].parentStory;
break;
default:
myObject = "None";
break;
}
break;
case 1:
myObject = app.activeDocument;
break;
case 2:
switch(app.selection[0].constructor.name){
case "Word":
case "TextStyleRange":
case "Line":
case "Paragraph":
case "TextColumn":
case "Text":
case "TextFrame":
if(app.selection[0].contents != ""){
myObject = app.selection[0].texts.item(0);
myCheckSelection = true;
}
else{
myObject = "None";
}
break;
default:
myObject = "None";
break;
}
break;
}
}
else{
myObject = "None";
}
myDialog.destroy();
return [myObject, myCheckSelection];
}
function myTextCleanup(myObject, myCheckSelection){
var myScriptFileName, myFindChangeFile, myFindChangeFileName, myScriptFile, myResult;
var myFindChangeFile = myFindFile("JSFindChangeMIC.txt")
if(myFindChangeFile != null){
var myResult = myFindChangeFile.open("r", undefined, undefined);
if(myResult == true){
//Clear any existing find/change settings.
app.changePreferences = NothingEnum.nothing;
app.findPreferences = NothingEnum.nothing;
//Loop through the find/change operations.
do{
myLine = myFindChangeFile.readln();
//Ignore comment lines and blank lines.
if((myLine.substring(0,2)!="//")&&(myLine != "")){
myFindChangeArray = myLine.split("\t");
//The first field in the line is the FindWhat string.
eval("app.findPreferences.properties = " + myFindChangeArray[0]);
//The second field in the line is the ChangeTo string.
eval ("app.changePreferences.properties = " + myFindChangeArray[1]);
//The third field in the line can be either "once" or "all".
//If it's "all", keep on searching until no instances of the
//search text are found, if it's "once," search just once.
myFindLimit = myFindChangeArray[2];
if(myFindLimit == "once"){
myFoundItems = myObject.search(app.findPreferences.findText, undefined, undefined, app.changePreferences.changeText);
}
else{
var myLoopLimit = 0;
outsideloop:
do{
//Because it's easy to end up in an endless loop when you set myFindLimit to "all", we need
//to provide a way to get out of the loop.
myFoundItems = myObject.search(app.findPreferences.findText, undefined, undefined, app.changePreferences.changeText);
myLoopLimit ++;
if(myLoopLimit > 100){
var myResult = confirm("Your find/change operation has been run 100 times. Do you want to continue?");
if(myResult == false){
break outsideloop;
}
else{
myLoopLimit = 0;
}
}
if(myCheckSelection == true){
//If myCheckSelection is true, reacquire a reference to the selection each time through the loop.
//You need to do this because deleting/adding characters has the potential to invalidate the
//text reference you're using.
myObject = app.selection[0];
}
}while(myFoundItems.length > 0);
}
//Reset the find/change preferences after each search.
app.changePreferences = NothingEnum.nothing;
app.findPreferences = NothingEnum.nothing;
if(myCheckSelection == true){
//If myCheckSelection is true, reacquire a reference to the selection each time through the loop.
//You need to do this because deleting/adding characters has the potential to invalidate the
//text reference you're using.
myObject = app.selection[0];
}
}
} while(myFindChangeFile.eof == false);
myFindChangeFile.close();
}
}
}
function myFindFile(myFileName){
var myFile;
try{
var myScriptFileName = app.activeScript;
//Get a file reference to the script.
var myScriptFile = File(myScriptFileName);
//Get a reference to the folder containing the script.
var myFolder = myScriptFile.parent;
//Look for the file name in the folder.
if(myFolder.getFiles(myFileName).length != 0){
var myFile = myFolder.getFiles(myFileName)[0];
}
else{
throw "error"
}
}
catch (myError){
myFile = File.openDialog("Choose the file containing your find/change list");
}
return myFile;
}
X