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

How can I refresh the Photoshop UI before displaying an alert()?

Engaged ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

I have a script that moves the layers on a document to new locations then displays an alert() dialog to remind the user what s/he should do next. The problem is that when the alert() dialog appears the layers appear to be in their old positions. When the user closes the alert() dialog the PS UI immediately refreshes and shows the layers in their new positions. Is there any way to force or allow the PS UI to refresh before I display the alert() dialog? Thanks.

TOPICS
Actions and scripting

Views

1.3K

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

correct answers 1 Correct answer

Community Expert , Jun 05, 2019 Jun 05, 2019

​

refresh();

Votes

Translate

Translate
Adobe
Community Expert ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

​

refresh();

JJMack

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
Engaged ,
Jun 05, 2019 Jun 05, 2019

Copy link to clipboard

Copied

That's what I needed. Thanks.

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
Advocate ,
Jan 01, 2021 Jan 01, 2021

Copy link to clipboard

Copied

LATEST

Im going benanas why a refresh still doesnt help when trying to edit a smartobject. My code is run before that windows is openened even when i try a sleep, redraw or a refresh?!?!

// Save JPOG from places smartbojects
// https://community.adobe.com/t5/photoshop/smart-object-automation-script/td-p/8877231?page=1

#target photoshop


function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };

if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theName = myDocument.name.match(/(.*)\.[^\.]+$/)[1];
    var thePath = myDocument.path;
    var theLayer = myDocument.activeLayer;
    // jpg options;
    var jpgopts = new JPEGSaveOptions();
    jpgopts.embedProfile = true;
    jpgopts.formatOptions = FormatOptions.STANDARDBASELINE;
    jpgopts.matte = MatteType.NONE;
    jpgopts.quality = 8;
    // check if layer is smart object;
    if (theLayer.kind != "LayerKind.SMARTOBJECT") {
        alert("selected layer is not a smart object")
    } else {
        // select files;
        if ($.os.search(/windows/i) != -1) {
            var theFiles = File.openDialog("please select files", "*.psd;*.tif;*.jpg;*.jpeg;", true)
        } else {
            var theFiles = File.openDialog("please select files", getFiles, true)
        };
        // select Folder;
        // var theFolder = Folder.selectDialog("select folder");
        if (theFiles) {
            // var theFiles = theFolder.getFiles(/\.(jpg|tif|eps|psd|png)$/i);
            // Select destination folder
            var destinationFolder = Folder.selectDialog("Please select a destination folder");
            // work through the array;
            for (var m = 0; m < theFiles.length; m++) {
                // replace smart object;
                // theLayer = replaceContents(theFiles, theLayer);
                // var editFile = runMenuItem(stringIDToTypeID('placedLayerEditContents'));
                var editSO = editContent(theFiles[m]);
                if(editSO){
                    app.refresh()
                    alert(app.activeDocument)
                    // var edtDoc = app.activeDocument;
                    // alert(edtDoc)
                    // var size= getSmartObjectInternalSize();
                    // alert(size.width)
                    // var theNewName = theFiles[m].name.match(/(.*)\.[^\.]+$/)[1];
                    //save jpg;
                    // myDocument.saveAs((new File(destinationFolder.toString() + "/" + theName + "_" + theNewName + ".jpg")), jpgopts, true);

                }
            }
        };
    }
};

////// get psds, tifs and jpgs from files //////
    function getFiles(theFile) {
        if (theFile.name.match(/\.(psd|tif|png|jpg|jpeg)$/i) != null || theFile.constructor.name == "Folder") {
            return true
        };
    };
////// replace contents //////
function replaceContents(newFile, theSO) {
    app.activeDocument.activeLayer = theSO;
    // =======================================================
    var idplacedLayerReplaceContents = stringIDToTypeID("placedLayerReplaceContents");
    var desc3 = new ActionDescriptor();
    var idnull = charIDToTypeID("null");
    desc3.putPath(idnull, new File(newFile));
    var idPgNm = charIDToTypeID("PgNm");
    desc3.putInteger(idPgNm, 1);
    executeAction(idplacedLayerReplaceContents, desc3, DialogModes.NO);

    return app.activeDocument.activeLayer
};

function editContent(newFile){
    var desc80 = new ActionDescriptor();
    executeAction( stringIDToTypeID('placedLayerEditContents'), desc80, DialogModes.NO );
    // app.refresh();
    // $.sleep(1000);
    function placeImage(theFile){
        
        if(app.documents.length > 1){
            alert(app.documents.length)
            var desc174 = new ActionDescriptor();
            desc174.putInteger( cTID('Idnt'), 885 );
            desc174.putPath( cTID('null'), new File(newFile));
            // desc174.putPath( cTID('null'), new File( "/Volumes/_MINDFLOW/_MINDFLOW/CLIENTS/Allusion/Export/Mockups/Rombout-Mockup-01-v8/Mockuo-08-GRID-Tags-Drk.jpg" ) );
            desc174.putBoolean( cTID('Lnkd'), true );
            desc174.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
                var desc175 = new ActionDescriptor();
                desc175.putUnitDouble( cTID('Hrzn'), cTID('#Pxl'), 0.000000 );
                desc175.putUnitDouble( cTID('Vrtc'), cTID('#Pxl'), 0.000000 );
            desc174.putObject( cTID('Ofst'), cTID('Ofst'), desc175 );
            desc174.putUnitDouble( cTID('Wdth'), cTID('#Prc'), 234.782609 );
            desc174.putUnitDouble( cTID('Hght'), cTID('#Prc'), 234.697509 );
            executeAction( cTID('Plc '), desc174, DialogModes.NO );
        } else {
            $.sleep(500);
            placeImage(theFile)
        }
    }
    

    // app.activeDocument.close(SaveOptions.SAVECHANGES);
    return true
}

function getSmartObjectInternalSize() {
	// =======================================================
	var idplacedLayerEditContents = stringIDToTypeID( "placedLayerEditContents" );
    var desc17 = new ActionDescriptor();
	executeAction( idplacedLayerEditContents, desc17, DialogModes.NO );
	
	var size=new Object();
	size.width=app.activeDocument.width.as("pixels");
	size.height=app.activeDocument.height.as("pixels");
	
	// app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
	return size;
}

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