0
JS CS2: Image Link

/t5/indesign-discussions/js-cs2-image-link/td-p/1148188
Apr 03, 2008
Apr 03, 2008
Copy link to clipboard
Copied
Is it possible to store in a variable the file name of an image that is selected in a document?
Cheers
Norbert
Cheers
Norbert
TOPICS
Scripting
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/indesign-discussions/js-cs2-image-link/m-p/1148189#M278090
Apr 03, 2008
Apr 03, 2008
Copy link to clipboard
Copied
Sorry forgot to mention that the selected item could be jpeg/pdf/eps tiff.
Regards
Norbert
Regards
Norbert
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/indesign-discussions/js-cs2-image-link/m-p/1148190#M278091
Apr 03, 2008
Apr 03, 2008
Copy link to clipboard
Copied
I found this code snippet in the forum but this only works on jpegs or tiffs and not on eps/ai or tiffs.
Any help will be much appreciated.
Cheers
Norbert
var myString = "";
myDoc=app.activeDocument
myImage = myDoc.selection[0].images[0];
myCurrLink = myImage.itemLink;
myName = getFileNameOnly (myCurrLink.name);
alert(myString);
function getFileNameOnly (myFileName)
{
var myResult = myFileName.lastIndexOf(".");
if (myResult == -1)
{
myString = myFileName;
}
else
{
myString = myFileName.substr(0, myResult);
}
}
Any help will be much appreciated.
Cheers
Norbert
var myString = "";
myDoc=app.activeDocument
myImage = myDoc.selection[0].images[0];
myCurrLink = myImage.itemLink;
myName = getFileNameOnly (myCurrLink.name);
alert(myString);
function getFileNameOnly (myFileName)
{
var myResult = myFileName.lastIndexOf(".");
if (myResult == -1)
{
myString = myFileName;
}
else
{
myString = myFileName.substr(0, myResult);
}
}
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-cs2-image-link/m-p/1148191#M278092
Apr 03, 2008
Apr 03, 2008
Copy link to clipboard
Copied
For EPS and AI, use epss[0] instead of images[0]
Peter
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-cs2-image-link/m-p/1148192#M278093
Apr 04, 2008
Apr 04, 2008
Copy link to clipboard
Copied
... but then you need to know the type of image, which could be epss, images, picts, pdfs, or wmfs (maybe some more). It's safer to avoid that and use "graphics" instead:
try
{
alert (File (app.selection[0].graphics[0].itemLink.filePath).name)
}
catch (_)
{
alert ("Selection doesn't contain any images.")
}
Peter
try
{
alert (File (app.selection[0].graphics[0].itemLink.filePath).name)
}
catch (_)
{
alert ("Selection doesn't contain any images.")
}
Peter
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

Guest
AUTHOR
/t5/indesign-discussions/js-cs2-image-link/m-p/1148193#M278094
Apr 06, 2008
Apr 06, 2008
Copy link to clipboard
Copied
Thanks very much Peter!!
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
New Here
,
LATEST
/t5/indesign-discussions/js-cs2-image-link/m-p/1148194#M278095
Apr 15, 2008
Apr 15, 2008
Copy link to clipboard
Copied
Something like this may work too...<br /><br />var filenameVariable = ""; <br />g = app.activeDocument.allGraphics;<br />for (i=0; i<g.length; i++){<br /> if (g.itemLink == null) {<br /> i++;}<br /> else {<br /> filenameVariable = g.itemLink.name;<br />}<br />}
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

