Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Rename (with suffix) and relink an selection images

Community Beginner ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

Is it possible by means of a javascript to rename a selection of images of a document in a bulk with a suffix and relink. (For example: filename.jpg to filename_C.jpg)

TOPICS
Scripting

Views

252

Likes

Translate

Translate

Report

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

correct answers 1 Correct answer

Adobe Community Professional , Apr 21, 2021 Apr 21, 2021
Yes, you should familiarize yourself with the File object and Link object. Link.copyLink(File) is going to be your primary mode of doing so.  Edited with a demonstration (you'll want graphic containers (ie rectangles and/or ovals) selected):  var sels = app.selection; var suffix = "_C"; var extRegEx = /\.[a-zA-Z]+$/gi; var aLink, linkName, linkExt, linkNameNoExt; for (var i = 0; i < sels.length; i++) { try { aLink = sels[i].graphics[0].itemLink; linkName = aLink.filePath; ...

Likes

Translate

Translate
Adobe Community Professional ,
Apr 21, 2021 Apr 21, 2021

Copy link to clipboard

Copied

Yes, you should familiarize yourself with the File object and Link object. Link.copyLink(File) is going to be your primary mode of doing so.  Edited with a demonstration (you'll want graphic containers (ie rectangles and/or ovals) selected): 

 

 

var sels = app.selection;
var suffix = "_C";
var extRegEx = /\.[a-zA-Z]+$/gi;
var aLink, linkName, linkExt, linkNameNoExt;
for (var i = 0; i < sels.length; i++) {
   try {
       aLink = sels[i].graphics[0].itemLink;
       linkName = aLink.filePath;
       linkExt = linkName.match(extRegEx)[0];
       linkNameNoExt = linkName.replace(extRegEx, "");
       aLink.copyLink(File(linkNameNoExt + suffix + linkExt));
   } catch(e) {}
}

 

 

 

 

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Note that this creates a copy of the image in its original location, rather than renames it. But it's the easiest way to do it. 

Likes

Translate

Translate

Report

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Thanks Brain311 it works!!!

And is it also possible with a selection in the 'links' panel (selection of images on different pages)?

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

No. Those selections are not accessible. Selections only work on a single spread. If you want it to operate on images across pages, you'll need some kind of logic in the code to grab the right ones. 

Likes

Translate

Translate

Report

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

Ok! Thanks!

Likes

Translate

Translate

Report

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
Adobe Community Professional ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

A fine to place to start is to get allGraphics of a Document object, then iterate through them. 

 

var ags = app.activeDocument.allGraphics;
var aLink;
for (var i = 0; i < ags.length; i++) {
    try {
        aLink = ags[i].itemLink;
        //your if (someCondition) code here
        //look at the Link object API here: 
        //https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Link.html
    } catch(e) {}
} 

 

Likes

Translate

Translate

Report

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 ,
Apr 22, 2021 Apr 22, 2021

Copy link to clipboard

Copied

LATEST

Whoww... hat is a bit too complicated for me

Likes

Translate

Translate

Report

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