• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

JS CS2: Image Link

Guest
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
TOPICS
Scripting

Views

407

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
Guest
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

Votes

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
Guest
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);
}
}

Votes

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 Expert ,
Apr 03, 2008 Apr 03, 2008

Copy link to clipboard

Copied

For EPS and AI, use epss[0] instead of images[0]

Peter

Votes

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 Expert ,
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

Votes

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
Guest
Apr 06, 2008 Apr 06, 2008

Copy link to clipboard

Copied

Thanks very much Peter!!

Votes

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
New Here ,
Apr 15, 2008 Apr 15, 2008

Copy link to clipboard

Copied

LATEST
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 />}

Votes

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