Skip to main content
dublove
Legend
June 6, 2025
Answered

How to make a pop-up tip automatically close in 2 seconds

  • June 6, 2025
  • 2 replies
  • 492 views

I want the “alert(”Existing table header“);” to disappear automatically in 2 seconds!
I found a code from the internet and it doesn't seem right.

  $(document).ready(function() {
        // Show warning box
        $("#alert-box").fadeIn(500, function() {
            // Automatically turns off after a certain period of time (e.g. 3 seconds)
            setTimeout(function() {
                $("#alert-box").fadeOut(500);
            }, 3000); // 3000 milliseconds = 3 seconds
        });
    });

 

My original code.

var cell = app.activeDocument.selection[0].parent;
var myTable = cell.parent;

firstRow = myTable.rows[0];
//add 1 row at the table top
if ((firstRow.rowType !== RowTypes.HEADER_ROW) && (myTable.rows[0].cells[0].contents !==contName))
    {
    dupeTopRow(myTable);
    myTable.rows.add(LocationOptions.BEFORE, myTable.rows[0]);
/**
* duplicate the first row af a myTable
* @ param the myTable
* @ return void
*/
function dupeTopRow(t){
    var newRow = t.rows.add(LocationOptions.BEFORE, t.rows[0]);
    var newCell = newRow.cells
    var lr = t.rows[1].cells
    for (var i = 0; i < newCell.length; i++){
        newCell[i].properties = lr[i].properties;
    };  
}
}
else{
alert("Existing table header ")
exit ();
}

 Thnak you very much.

Correct answer Eugene Tyson

I don't think you can use alert
It blocks script execution until the user manually closes it.

There is no built-in way to close an alert() after a timeout, in ExtendScript.

 

You have to create your own tooltip witha. palette maybe that disappears this seems to work

function showAutoCloseDialog(message, duration) {
    var win = new Window("palette", "Notice", undefined, {closeButton: false});
    win.add("statictext", undefined, message);
    win.layout.layout(true); // Force layout before showing
    win.show();
    win.update();            // Force redraw before sleep

    $.sleep(duration);       // Wait for the specified duration
    win.close();             // Then close the window
}

// Call the function
showAutoCloseDialog("This will close in 2 seconds", 2000);

 

2 replies

Eugene TysonCommunity ExpertCorrect answer
Community Expert
June 7, 2025

I don't think you can use alert
It blocks script execution until the user manually closes it.

There is no built-in way to close an alert() after a timeout, in ExtendScript.

 

You have to create your own tooltip witha. palette maybe that disappears this seems to work

function showAutoCloseDialog(message, duration) {
    var win = new Window("palette", "Notice", undefined, {closeButton: false});
    win.add("statictext", undefined, message);
    win.layout.layout(true); // Force layout before showing
    win.show();
    win.update();            // Force redraw before sleep

    $.sleep(duration);       // Wait for the specified duration
    win.close();             // Then close the window
}

// Call the function
showAutoCloseDialog("This will close in 2 seconds", 2000);

 

dublove
dubloveAuthor
Legend
June 7, 2025

Hi Eugene Tyson

Thank you very much.
It runs, that's what I was having trouble with before it popped up.
I add exit ();to the end .

After to read the seconds and it quits.

 

It's just that the font is a little small for this prompt, is there any way to enlarge the font.

Community Expert
June 7, 2025

Dunno - presume after

function showAutoCloseDialog(message, duration) {
    var win = new Window("palette", "Notice", undefined, {closeButton: false});
    
    var txt = win.add("statictext", undefined, message);

add

  // Change font size
    txt.graphics.font = ScriptUI.newFont("Arial", "REGULAR", 18); // Change 18 to desired size

 maybe

m1b
Community Expert
Community Expert
June 7, 2025

@dublove the first code looks like jquery code, not ExtendScript—it won't help you at all.

 

In Indesign, I don't know how to make a dialog disappear automatically in 2 seconds. Maybe someone else will.

- Mark

dublove
dubloveAuthor
Legend
June 7, 2025

@m1b 

Thanks for the care.
Look into duplicating multi-row table headers. Your original writeup for me on converting a selection to a table header, I'm having a hard time controlling it.


There are also issues with opening images in PS by default and the images not updating, as well as images not updating after modification and the script not working.