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

Scripting: Toggle "Proof Colors"

Community Beginner ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

Hey,

I want to create a scrip to toggle "Proof Colors" on/off and to get the state of "Proof Colors" (currently on or off).

You can toggle it manually using:

- View -> Proof Colors

or

- Win: Ctrl+Y  /  Mac: Cmd+Y

Now I want to script this procedure but I have following problems:

- There is no related function in PS Scripting Guide

- If you toggle "Proof Colors" while ScriptListener is active there are no entries in log.

- If you toggle "Proof Colors" while recording an "Action" there are no steps recorded.

Do you have any ideas or workarounds to do this?

Regards Jens

Used Setup: PS CC2017.1, Win10

TOPICS
Actions and scripting

Views

602

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

To toggle you need to know the current state Photoshop is in for either its UI for all documents being processes or if it is a toggle per document being edited the state the documents are  in for example guides per document. The global state can be keep in a custom script option, for document toggle I use each the document's metadata info field.  The other part is knowing the current state you need to be able to change the state  via DOM or Action Manager Code.

As you point out View -> Proof Colors is a toggle there is no need to script it.  If you want to toggle it in an action or script it  execute a menu item.  In action you use insert menu item.  Getting its current toggle state is a different matter. It may be possible.

#target photoshop

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

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

function toggleproofcolor() {

  // Select

  function step1(enabled, withDialog) {

    if (enabled != undefined && !enabled)

      return;

    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("toggleProofColors"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, dialogMode);

  };

  step1();     

};

Adobe introduced a bug in CC 2015.5  that can break script that use metadata for things like toggle.  I needed to add script events to CC 2015.5 and CC 2017 to add garbage into the info field to work around Adobe bug.   Here is a  toggle for centering guide line for documents.  They will reposition  when you chang canvas size when you toggle them on and off after change canvas. Note this will n]ot work in CC 2015.5 and CC 2017 unless you add garbage to metadat info field.

/* ======================================================================================

// 2015  John J. McAssey (JJMack)  http://www.mouseprints.net/

// 

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

//

// This script is designed to Toggle centering guides.

//      assign a shortcut I use this in an action assigned to F12.

//

// ===================================================================================== */

/*

<javascriptresource>

<about>$$$/JavaScripts/AddRemoveCenterGuides/About=JJMack's AddRemoveCenterGuides.^r^rCopyright 2009 Mouseprints.^r^rRun twice script utility for action.^r^rFirst Run Set Guides on camvas bounds and center.^rSecond Run clears the set guides.</about>

<category>JJMack's Action Run Twice Utility</category>

</javascriptresource>

*/

if (app.documents.length > 0) app.activeDocument.suspendHistory('ToggleCenterGuides','main()' );

else alert("You must have at least one open document to run this script!");

///////////////////////////////////////////////////////////////////////////////////////////

function main() {

if (app.activeDocument.info.instructions.indexOf("<CenterGuides>") == -1 ){ // no footprint fisrt useage

var orig_ruler_units = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS; // Set the ruler units to PIXELS

try {

activeDocument.guides.add(Direction.VERTICAL, 0);

activeDocument.guides.add(Direction.VERTICAL, activeDocument.width/4);

activeDocument.guides.add(Direction.VERTICAL, activeDocument.width/2);

activeDocument.guides.add(Direction.VERTICAL, activeDocument.width*3/4);

activeDocument.guides.add(Direction.VERTICAL, activeDocument.width);

activeDocument.guides.add(Direction.HORIZONTAL, 0);

activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height/4);

activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height/2);

activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height*3/4);

activeDocument.guides.add(Direction.HORIZONTAL, activeDocument.height);

  }

// display error message if something goes wrong

catch(e) { alert(e + ': on line ' + e.line, 'Script Error', true); }

app.preferences.rulerUnits = orig_ruler_units; // Reset units to original settings

// put footprint in metadata info instructions

app.activeDocument.info.instructions = app.activeDocument.info.instructions + "<CenterGuides>" + " Show" + "</CenterGuides>";

}

else {

clearGuides();

// Remove footprint from metadata info instructions

before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexOf("<CenterGuides>"));

afterOffset = app.activeDocument.info.instructions.indexOf("</CenterGuides>") + "</CenterGuides>".length;

after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);

//alert ("before = " + before + " after = " + after);

app.activeDocument.info.instructions = before + after;

//alert("app.activeDocument.info.instructions = " + app.activeDocument.info.instructions); 

}

}

//////////////////////////////////////////// Action Manager Code to Clear all Guides ///////////////////////////////////

function clearGuides() {

   var id556 = charIDToTypeID( "Dlt " );

       var desc102 = new ActionDescriptor();

       var id557 = charIDToTypeID( "null" );

           var ref70 = new ActionReference();

           var id558 = charIDToTypeID( "Gd  " );

           var id559 = charIDToTypeID( "Ordn" );

           var id560 = charIDToTypeID( "Al  " );

           ref70.putEnumerated( id558, id559, id560 );

       desc102.putReference( id557, ref70 );

   executeAction( id556, desc102, DialogModes.NO );

};

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

I ran several tests and it works very well here.

Check this script:

cTID = function(s) {

    return app.charIDToTypeID(s);

};

sTID = function(s) {

    return app.stringIDToTypeID(s);

};

// ToggleProof Colors

function ToggleProofColors() {

    // Select

    function tpc(enabled, withDialog) {

        if (enabled != undefined && !enabled)

            return;

        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);

        var desc1 = new ActionDescriptor();

        var ref1 = new ActionReference();

        ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("toggleProofColors"));

        desc1.putReference(cTID('null'), ref1);

        executeAction(cTID('slct'), desc1, dialogMode);

    };

    tpc(); // Select

};

ToggleProofColors.main = function() {

    ToggleProofColors();

};

ToggleProofColors.main();

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

There is no problem toggling proof colors that a function built into Photoshop.   How do you find out which of the two states that Photoshop is currently using in its UI. With your eyes you can see the if the check is in the UI how does a script see the state?

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

JJMack  escreveu

There is no problem toggling proof colors that a function built into Photoshop.   How do you find out which of the two states that Photoshop is currently using in its UI. With your eyes you can see the if the check is in the UI how does a script see the state?

Screenshot_3.jpg

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 ,
Jul 14, 2017 Jul 14, 2017

Copy link to clipboard

Copied

LATEST

mauricior6328708  wrote

JJMack   escreveu

There is no problem toggling proof colors that a function built into Photoshop.   How do you find out which of the two states that Photoshop is currently using in its UI. With your eyes you can see the if the check is in the UI how does a script see the state?

Screenshot_3.jpg

That is not script code a script has code not eyes...

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