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

How to get the image path without switching the selection tool?

Guide ,
Jun 24, 2025 Jun 24, 2025

Sometimes, it is necessary to switch to the direct selection tool (white arrow) in order to recognize it.
Sometimes, it is again necessary to use the selection tool (black arrow) to recognize it.

dublove_0-1750750527652.jpeg

For example:
// open the paths in photoshop
openPathsInPhotoshop(paths);
This requires the selection tool.
If it is a direct selection tool, it will report an error.

dublove_1-1750750567357.jpeg

 

Is it possible to pass through?
Because sometimes we don't need to distinguish between them.

 

Thank you very much.

TOPICS
Scripting
1.3K
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 , Jun 24, 2025 Jun 24, 2025

I think you need a function to check your selection for an image, something like this:

 

main()

function main(){
    //if checkSelection() returns no image send alert and stop the script
    if (checkSelection() == undefined) {
        alert("No Image Selected")
        return
    } 
    //get the file path
    var fp = checkSelection()
    alert("This selection’s file path: " + fp)
}



/**
* Checks if a selection is an image or contains an image 
* @ return the image file path 
*/
function c
...
Translate
Community Expert , Jun 24, 2025 Jun 24, 2025

Try this for your main function:

(function () {

    if (0 === app.documents.length)
        return alert('Please open a document and try again');

    var doc = app.activeDocument,
        items = doc.selection;

    if (0 === items.length)
        return alert('Please select a picture frame');

    // collect paths for each selected item
    var paths = [],
        links = [];

    for (var i = 0; i < items.length; i++) {

        var item = items[i];

        // maybe user selected the image,
...
Translate
Guide ,
Jun 24, 2025 Jun 24, 2025

Sometimes it is necessary to distinguish between them.
Sometimes it is not necessary to distinguish them.

That's the point of having two tools.

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 ,
Jun 24, 2025 Jun 24, 2025

I think you need a function to check your selection for an image, something like this:

 

main()

function main(){
    //if checkSelection() returns no image send alert and stop the script
    if (checkSelection() == undefined) {
        alert("No Image Selected")
        return
    } 
    //get the file path
    var fp = checkSelection()
    alert("This selection’s file path: " + fp)
}



/**
* Checks if a selection is an image or contains an image 
* @ return the image file path 
*/
function checkSelection(){
    var sel, p
    //check for a selection
    if (app.activeDocument.selection.length > 0) {
        //check the selection for an image
        sel = app.activeDocument.selection[0];
        if (sel.constructor.name === "Image") {
            p = sel.itemLink.filePath
        } else {
            try {
                p = sel.images[0].itemLink.filePath
            }catch(e){}     
        }
    } 
    //retuns a file path or undefined
    return p
}

 

 

Screen Shot 34.png

 

 

 

 

 

 

 

Screen Shot 36.png

 

 

Screen Shot 37.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 ,
Jun 24, 2025 Jun 24, 2025

Hi rob day.

Thank you very much.

Yes, need to be judging the different states of choice.
This is worth learning from me.
Now it's time to go with the m1b option for now, time is running out.

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 Beginner ,
Sep 12, 2025 Sep 12, 2025
LATEST

To get the image path without switching tools: Layers Panel: Open the Layers panel and hover over the image to see its details. Info Panel: Open the Info panel (Window > Info) for position and path details. Right-click: Right-click the image and select "Properties" or "Reveal in Finder/Explorer". These methods allow you to access the path easily!

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