Skip to main content
Known Participant
October 30, 2013
Question

Remove spaces and lowercase image link names

  • October 30, 2013
  • 4 replies
  • 2254 views

Hey Script forum,

I was wondering if anyone knows of a script that could remove spaces and lowercase the link names in a document, and relink the image. I'm getting some errors wen exporting ePubs about spaces and uppercase letters. Obviously I can change them manually, but it would be so nice if it could be done automatically.

I tried to run a search for such a great tool/script, but so far I've come up flat.

Thanks,
Tara

This topic has been closed for replies.

4 replies

Sergey_Anosov
Participating Frequently
November 3, 2013

Hi!

Maybe this script will be helpful:

https://sites.google.com/site/dtpscripting/indesign-scripts/standardlinksnames-jsx
Although it does not lowercase links names, but it could be modified for that purpose.

Jongware
Brainiac
November 2, 2013

Is it possible that removing spaces may cause a duplicate filename? (Of course it *can*, but does your workflow prevent it right from the start?)

pixxxelschubser
Adobe Expert
November 2, 2013

You can try something like this:

// relink_ImgWithCleanedName.jsx

// http://forums.adobe.com/thread/1325315?tstart=0

// Remove spaces and lowercase image link names (and relink)

// required: an opened document with placed image

// regards pixxxelschubser

var imgs = app.activeDocument.allGraphics;

if (imgs.length != 0) {

//var imgs = app.activeDocument.links;

var img = imgs[0].itemLink;

if (img.status  == LinkStatus.NORMAL ) {

var old_imgName = img.name;

var old_imgPath = img.filePath;

var old_imgFile = File (old_imgPath);

//var new_imgName = old_imgName.replace(/ /g,'').toLowerCase();

// --> does what you want -  but I prefer this:

var new_imgName = old_imgName.replace(/ /g,'_').toLowerCase();

old_imgFile.rename(new_imgName);

var new_namedFile = File (old_imgFile.parent.fsName+"//"+new_imgName);

img.relink(new_namedFile);

img.update();

} else {alert("LinkStatus von: "+img.name + " --> " +img.status)}

} else {alert("no linked graphics")}

All you have to do is to add a loop through all graphics linked items.

Have fun

Inspiring
January 21, 2019

So how do you add a loop to this code so that it goes through all the images in the open document?

pixxxelschubser
Adobe Expert
January 21, 2019

At first: this thread is more than 5 years old.

But anyway:

for ( i=0; i <= img.length-1; i++ ) {

    //…

    }

Brainiac
October 31, 2013
TL PriceAuthor
Known Participant
October 31, 2013

Thanks Vandy,

It's close to what I'm looking for, but still leaves a lot of manual changing. But thank you so much for forewarding it to me. I'll definitely have use for it in other projects.

Tara