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

Saving Photoshop document with extendscript in background

Contributor ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

Hello,

 

When I save changes to a Photoshop document - already saved to disk - with the app.activeDocument.save() command, a progress modal dialog is displayed:

 

ScreenCapture 2023-04-17 à 09.20.12.jpg

But if I use the Save menu item of the File menu, the recording is done as a background process (without modal progression) and I can continue to work.

 

ScreenCapture 2023-04-17 à 09.20.55.jpg

 

So, using extendscript with Photoshop 13 (CS6), how can I save the active document as background process without this annoying modal window?

 

Thank you.

 

 

TOPICS
Actions and scripting

Views

2.1K

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
Adobe
Community Expert ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

Offhand, I would say this may not be possible, as when you run a script, you can't do anything until the script completes. However, you might want to try recording the save with AM code rather than DOM. Maybe that might work.

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
Contributor ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

Thank you for your answers.

@Stephen_A_Marsh: just tried but DialogModes.NO doesn't change anything.

 

Chuck, I don't understand what is a record with AM. Is it the ScriptListener?

I tried with the code written by the ScriptListener when using the Save menu item but the result is the same: I always have this annoying modal progress window.

 

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
Community Expert ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

quote

Thank you for your answers.

@Stephen_A_Marsh: just tried but DialogModes.NO doesn't change anything.


By @frmorel

 

That's a shame. What happens if you record the save command into an action? A script can play an action...

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
Community Expert ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

Have you tried something like:

 

var savedDisplayDialogs = app.displayDialogs;
app.displayDialogs = DialogModes.NO;
app.activeDocument.save();
app.displayDialogs = savedDisplayDialogs;

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
Valorous Hero ,
Apr 17, 2023 Apr 17, 2023

Copy link to clipboard

Copied

This is possible by running an external script (or program) that simulates pressing Ctrl + S, provided that you have the background save mode enabled.

 

REM: In this case, the script must be in step-by-step mode for some time at the time the external program is launched, otherwise Photoshop will skip processing the keystrokes.

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
Contributor ,
Apr 21, 2023 Apr 21, 2023

Copy link to clipboard

Copied

LATEST

OK, I finally wrote an Applescript that launches a Photoshop action, because MacOS makes it difficult to directly call a menu-item.

So I have an extendscript that inserts a history step and then calls the Applescript (which itself calls an action)...

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
Contributor ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

@Stephen_A_Marsh  I didn't know that a script could perform an action. It can be interesting.

 

@r-bin   indeed, it must be possible but it becomes complicated for what I would like to do.

 

Maybe I'm doing it wrong and there are other ways to do what I want.

When I save the changes of the active document, I would like a history step to be created (with an extendscript script).

 

I tried to run the history step creation script with the Scripts Events Manager but there are problems:

- if I run my extendscript on the "start saving" event, the history step is created even if the saving of the document is not completed (error or cancellation by the user). So this solution is not accurate.

- if I run my extendscript on the "saving document" event, the history step is created after the document is saved, and so the document appears as modified (and displays a save modal dialog if I close this document, which is rather painful).

 

Do you know another way to do what I would like?

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
Valorous Hero ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

I didn't really understand what you want and why you need a history step after document.save()
 
 

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
Community Expert ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

quote

@Stephen_A_Marsh  I didn't know that a script could perform an action. It can be interesting.

 

By @frmorel

 

A script can play an action, and an action can record the execution of a browsed script (that has not been installed) or the insert menu command of an installed script in the presets/scripts folder!

 

app.doAction("Molten Lead","Default Actions.atn");

// or

var actionName = "Molten Lead"; // Action to run
var actionSet = "Default Actions.atn"; // Action set to run
app.doAction(actionName,actionSet);

// or

playAction ('my action set', 'my action name')

function playAction(actionSet, actionName){
var idPly = charIDToTypeID( "Ply " );
    var desc2 = new ActionDescriptor();
    var idnull = charIDToTypeID( "null" );
        var ref1 = new ActionReference();
        var idActn = charIDToTypeID( "Actn" );
        ref1.putName( idActn, actionSet );
        var idASet = charIDToTypeID( "ASet" );
        ref1.putName( idASet, actionName );
    desc2.putReference( idnull, ref1 );
executeAction( idPly, desc2, DialogModes.NO );
}

 

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
Contributor ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

@Stephen_A_MarshThank you! I just tried with app.doAction but the result is the same (modal progress window). I think Chuck is right: when running an extenscript, you can't do anything until the script completes, so a modal window is displayed.

 

@r-bin 

It often happens that I try a little "weird" and complex things on the images that I process and I find it useful to have a step in my history: it allows me to see exactly what I have done since the document was last saved. Of course, when I'm not happy with my latest changes, I could use the Revert to Saved menu item, but that might undo actions I want to keep.
This script is not very important, it's just for a better working comfort.

In any case, I can keep the one I currently have: the one with the progress modal window.

 

(and sorry for my english, I used Google Translation)

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
Community Expert ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

quote

@Stephen_A_MarshThank you! I just tried with app.doAction but the result is the same (modal progress window). 


By @frmorel

 

Yes, I didn't hold much hope and was hoping for a pleasant surprise.

 

quote

I think Chuck is right: when running an extenscript, you can't do anything until the script completes, so a modal window is displayed.

 

He usually is! 

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
Valorous Hero ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

For windows try this script.

 

try {

ctrl_j();

ctrl_s();

app.refresh();

alert(1);

for (var i = 0; i < 100; i++) ctrl_j();

alert(2);

////////////////////////////////////////////////////////////////////////////////////////////
function ctrl_s()
    {
    var ctrl_s_exe_name = "C:\\Program Files\\Common Files\\Adobe\\Scripts\\UTIL\\ctrl_s.exe";

    try {
        var f = new File(ctrl_s_exe_name);

        if (f.exists)
            {
            f.execute();
            f = null;
            }
        else 
            alert("File not found\n\n" + f.fsName);
        }
    catch(e) { throw(e); }
    }

function ctrl_j()
    {
    try { 
        executeAction(stringIDToTypeID("copyToLayer"), undefined, DialogModes.NO); 
        } 
    catch(e) { throw(e); }
    }


} catch(e) { alert(e); }

 

First copy the exe-file https://disk.yandex.ru/d/HktKHYckuPt-eA

to the specified path.

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
Contributor ,
Apr 18, 2023 Apr 18, 2023

Copy link to clipboard

Copied

Thank you very much!

I would be eager to test this script... If I wasn't working on Mac 😞    (MacOS Sierra 10.12)

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