Quantcast
Channel: Adobe Community: Message List - InDesign Scripting
Viewing all articles
Browse latest Browse all 37788

Re: Delete character in file names

$
0
0

@Unique – so we do not work on InDesign files, but on files ending with .ttjs, right?

 

Are these .ttjs files related to the TouchThing game engine? I ask just out of curiosity…

 

Ok. In your question starting this thread, you are showing an ExtendScript snippet, that is working with the active InDesign file and is doing weird things to it.

Did you ever run it in InDesign having a file open?

 

In effect it duplicates the active document giving a new suffix to the duplicate.

This is an absolute No-No !! Never rename the suffix of an InDesign file from *.indd to other than *.indt. In your case it was getting the *.ps suffix which usually stands for a PostScript file.

 

Ah. And then, in the last line, that snippet is throwing an error:

 

"Copy of "Test.ps" cannot be saved.

File "Test.ps" is already open (error code: 1)."

 

 

Here an ExtendScript (JavaScript) to rename those .ttjs files (whatever those are).

You have to run it from InDesign or from the ESTK (ExtendScript Toolkit).

 

What the script will do:

 

Renaming .ttjs files as you suggested or your contributions here are showing:

Leaving alone the "XX_" at the start of the name followed by a digit of variable length.

 

Removing a possible string  beginning with a "_" plus an (nearly) arbitrary part until the suffix is reached.

 

In detail:

1. A dialog will prompt you to select one or more files with suffix .ttjs.

2. The script will work on every selected file with the right suffix.

Provided: the file with the new name does not exist already.

3. An alert is showing up when the script is done.

 

The script's action CANNOT be un-done. So be careful!

To my tests it does not overwrite existing files on Mac OS.

But first test this out carefully, expecially when working on Windows.

 

For scripters: there is a rename() method for the File class.
The script is tested on Mac OSX 10.6.8 with InDesign CS5.5.

 

Here the code:

 

//RenamingFiles_Suffix_ttjs_RUN-SCRIPT-FROM-INDESIGN.jsx//Uwe Laubender/**
* @@@BUILDINFO@@@ RenamingFiles_Suffix_ttjs_RUN-SCRIPT-FROM-INDESIGN.jsx !Version! Mon Dec 16 2013 17:47:48 GMT+0100
*///DESCRIPTION:Tested OK with OSX 10.6.8 with InDesign CS5.5, does not OVERWRITE existing files! 
var mySelectedFiles= File.openDialog("Select one or some files with suffix \"*.ttjs\":",undefined,true);if(mySelectedFiles === null){alert("Script canceled by user");exit()}; 
var counterSuccess= 0;
var counterNoSuccess= 0;
var counterWrongFileSuffix = 0; 
var myFiles = new Array(); for(var n=0;n<mySelectedFiles.length;n++){    if(mySelectedFiles[n].name.match(/\.ttjs$/)){        myFiles.push(mySelectedFiles[n]);        };    else{++counterWrongFileSuffix;};    }for(var n=0;n<myFiles.length;n++){     var myFileName = myFiles[n].name;     var notNeededString = myFileName.replace(/XX_\d+/,"").replace(/\.ttjs$/,"");    var myNewName = myFileName.replace(notNeededString,"");     var renamingSuccessful = myFiles[n].rename(myNewName);     if(renamingSuccessful){++counterSuccess;};    if(!renamingSuccessful){++counterNoSuccess;};     }; 
alert("Done!"+"\r"+     counterWrongFileSuffix+"\t"+"Files: wrong file suffix"+"\r"+    counterNoSuccess+"\t"+".ttjs files not renamed"+"\r"+"\r"+     counterSuccess+"\t"+".ttjs FILES RENAMED"+"\r"+"\r"+     mySelectedFiles.length+"\t"+"FILES SELECTED"     );

 

Since openDialog() and the File class are not unique to InDesign, the script could run successfully from e.g. Adobe Illustrator as well. Maybe all apps that support ExtendScript (not tested).

 

Uwe


Viewing all articles
Browse latest Browse all 37788

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>