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

How to obtain the path of an image inserted into a frame? I hope both selection tools work.

Guide ,
Aug 14, 2025 Aug 14, 2025

Using the Selection Tool and Direct Selection Tool
How do I obtain the path of an image pasted inside?

I tried using .parent, but it didn't work.

 var image = app.selection[0].parent;
var imagePath = image.itemLink.filePath;

 

The test file is here:

https://musetransfer.com/s/hlryv6cor 

 

    try {
        //alert(app.selection[0].constructor.name);
        if (app.selection[0].constructor.name == "Image") {
            //alert("here");
            var image = app.selection[0].parent;
            var imagePath = image.itemLink.filePath;
            //alert(imagePath);
        }
        else {
            var image = app.selection[0].images[0];
            var imagePath = image.itemLink.filePath;
            //alert(imagePath);
        }

    } catch (e) { return }

1010.png

TOPICS
How to , Scripting
822
Translate
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 2 Correct answers

Community Expert , Aug 14, 2025 Aug 14, 2025

Right, your if else statement trys to get the image inside of the Rectangle when it is selected.

 

Also, looks like there is some kind of corruption with your bottom 2 images—images[0] throws an error when the bottom image/frame is selected. Try allGraphics[0] — it works

 

try {
    if (app.selection[0].constructor.name == "Image") {
        var image = app.activeDocument.selection[0];
        var imagePath = image.itemLink.filePath;
    }
    else {
        var image = app.activeDocument.selec
...
Translate
Community Expert , Aug 19, 2025 Aug 19, 2025

Hi @dublove you seem to be struggling with this idea of "select tool" vs "direct selection tool". This is a false idea because with the selection tool we can select the frame OR the graphic (by clicking on the circle widget in the frame center). Instead, try to have a better understanding of what you have selected.

 

For scripting, this is my approach: I make a function that does all the heavy lifting. I use it and never have to think twice about it (until I find a bug!).

 

Here is an example, t

...
Translate
Community Expert ,
Aug 19, 2025 Aug 19, 2025

Check the validity of the selection—your script fails when the selected image and its frame is nested inside of another frame.

 

var selectedFrame = app.selection[0];
alert(selectedFrame.images[0].isValid)

 

I get this from your sample file when the selection contains nested frames—image[0] is not valid

 

Screen Shot 1.png

 

 

 

 

 

 

Translate
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
Guide ,
Aug 19, 2025 Aug 19, 2025

I definitely know the reason.
I am asking how to solve this problem.

Because the “paste inside” function is also commonly used.

Translate
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 ,
Aug 19, 2025 Aug 19, 2025

Because the “paste inside” function is also commonly used.

 

You can paste image frames into other image frames multiple levels deep—I would never do it because it ads unnecessary complexity to the page.

 

This selected image is buried 4 frames deep. If the top parent frame is the selection it gets harder to drill down via scripting and check for an image.

 

Screen Shot 3.png

Translate
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
Guide ,
Aug 14, 2025 Aug 14, 2025

Can only one image be opened by Photoshop at the same time?

 

This seems to be a dialog box popping up in PS.

Translate
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