Skip to main content
dublove
Legend
June 20, 2025
Question

The dialog box still won't, how to combine these 3 in a dropdown list?

  • June 20, 2025
  • 1 reply
  • 323 views

I want to replace it with another format under the original path.
Can these three be combined into a drop down list, for dialog boxes I always find it not so easy.

var selectedFrame = app.selection[0];
var link = selectedFrame.images[0].itemLink;
var linkPsd = link.linkResourceURI.replace(/\.[^\.]+$/, '.PSD');
var linkTif = link.linkResourceURI.replace(/\.[^\.]+$/, '.TIF');
var linkJpg = link.linkResourceURI.replace(/\.[^\.]+$/, '.JPG');

link.reinitLink(linkURI);

 

1 reply

rob day
Community Expert
Community Expert
June 20, 2025

You need a dialog? Something like this?

 

makeDialog();
var pp, lst;   
function makeDialog(){
    var theDialog = app.dialogs.add({name:"Choose a Preset", canCancel:true});
    lst = ["PDF", "TIF", "JPG"]
    with(theDialog.dialogColumns.add()){
        pp = dropdowns.add({stringList:lst, selectedIndex:0, minWidth:80});
    }
    if(theDialog.show() == true){
        pp = pp.selectedIndex
        main();
        theDialog.destroy();
	}
}


function main(){
    alert("Chosen Format: " + lst[pp]);
    //Do something with the preset here
}

 

 

 

dublove
dubloveAuthor
Legend
June 21, 2025

@rob day  @m1b 

"The direct selection tool(white arrow)"  seemingly not work here.


Already linked from jpg to Tif. but still showing ◬ and it doesn't refresh automatically?

 

Can the drop down list show only short PSD,TIF,JPG?
If Chinese, it seems to have been converted, it's very long and I can't see the end of it.

Can help me make two lines:
The first line shows the drop-down list: PSD TIF JPG
The second line shows the full path of the currently selected format.
To make it easier to look at to make sure it's the right one.

Thanks.

 

I use 

lst = [decodeURI(PSD), decodeURI(TIF), decodeURI(JPG)]

to solve Chinese garbage, but I will run into the problem of very long filenames later.

 

/*
Change image Link format.
Thanks to rob day m1b 
https://community.adobe.com/t5/indesign-discussions/the-dialog-box-still-won-t-how-to-combine-these-3-in-a-dropdown-list/m-p/15381260#M628897
*/

function main() {
    if (
        0 === app.documents.length
        || 0 === app.selection.length
        || 'Rentangle' === app.selection[0].constructor.name
    )
        return alert("Please select a frame that contains an image in an InDesign document.");
    var selectedFrame = app.selection[0];

    if (0 === selectedFrame.images.length)
        return alert("The selected frame does not contain an image.");

    var imageFile = new File(selectedFrame.images[0].itemLink.filePath);
    if (!imageFile.exists)
        return alert("The image file associated with the selected frame does not exist.");
    var link = selectedFrame.images[0].itemLink;
    var PSD = link.linkResourceURI.replace(/\.[^\.]+$/, '.PSD');
    var TIF = link.linkResourceURI.replace(/\.[^\.]+$/, '.TIF');
    var JPG = link.linkResourceURI.replace(/\.[^\.]+$/, '.JPG');
    makeDialog();
    var pp, lst;
    function makeDialog() {
        var theDialog = app.dialogs.add({ name: "Choose a Preset", canCancel: true });
        lst = [decodeURI(PSD), decodeURI(TIF), decodeURI(JPG)]
        with (theDialog.dialogColumns.add()) {
            pp = dropdowns.add({ stringList: lst, selectedIndex: 0, minWidth: 80, minHeight: 150, });

            staticTexts.add({ staticLabel: (decodeURI(lst[pp.selectedIndex])), fontSize: 6, });
        }
        if (theDialog.show() == true) {
            pp = pp.selectedIndex
            reLink();
            theDialog.destroy();
        }
    }

    function reLink() {
        link.reinitLink(encodeURI(lst[pp]));
    }
}
main();