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

Photoshop extendscript guides visibility?

Contributor ,
Jan 26, 2025 Jan 26, 2025

Hello,

 

I know the question concerning how to get guides visibility has already been asked but I found here that "guidesVisibility" is somehow defined:

https://ten-artai.com/photoshop-stringid-typeid-charid-list/

 

To get rulers visibility, I use this script :

var r = new ActionReference();
r.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "rulersVisibility" ) );
r.putEnumerated( charIDToTypeID( "Dcmn" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
var rulersVisible = executeActionGet(r).getBoolean(stringIDToTypeID("rulersVisibility"));

 

So, would it be possible to modify the above rulers visibility script to manage guides visibility?

 

TOPICS
Actions and scripting
392
Translate
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 ,
Jan 26, 2025 Jan 26, 2025

@frmorel 

 

I’m not sure if I understand correctly. Your code shows rulersVisibility and not guidesVisibility and always appears to return true whether or not you are using rulers or guides and whether or not they are visible.

 

The following code can toggle the guides on/off:

 

    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };
    var descriptor = new ActionDescriptor();
    var reference = new ActionReference();
    reference.putEnumerated(s2t("menuItemClass"), s2t("menuItemType"), s2t("toggleGuides"));
    descriptor.putReference(s2t("null"), reference);
    executeAction(s2t("select"), descriptor, DialogModes.NO);

 

Or:

 

app.runMenuItem(stringIDToTypeID('toggleGuides'));

 

If the guides states visibility of true or false can be correctly determined, then the toggle becomes more useful.

Translate
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 ,
Jan 27, 2025 Jan 27, 2025

One could also use menuBarInfo to get the value, but – again – this value does not seem to be updated immediately, so it is somewhat unreliable. 

Translate
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 ,
Jan 27, 2025 Jan 27, 2025

Thank you for your answers.

@Stephen Marsh  Sorry if I wasn't very clear.

I know that my code contains rulersVisibility, since I use it to get the visibility of the rulers. Last line of the code which works correctly for me is missing:

return rulersVisible;

I don't understand anything about Action Manager, so I tried to adapt this code by replacing rulersVisibility with guidesVisibility but it doesn't work.
So my question was: is it possible to adapt the initial code - the one that returns the visibility of the rulers - to know the visibility of the guides.
As you point out, it is not very relevant to execute a toggle without knowing the initial state (the visibility in this case).

Translate
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 ,
Jan 27, 2025 Jan 27, 2025

As I mentioned the setting may not update immediately. 

// determine guides visibility;
// 2025, use it at your own risk;
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var xxx = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu"));
for (var m = 0; m < xxx.count; m++) {
var thisOne = xxx.getObjectValue(m);
// get window menu;
if (thisOne.getString(stringIDToTypeID("title")) == "View") {
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(m).getList(stringIDToTypeID("submenu"));
}
};
// get show menu;
for (var m = 0; m < view_submenus.count; m++) {
var thisOne = view_submenus.getObjectValue(m);
if (thisOne.getString(stringIDToTypeID("title")) == "Show") {
var thisSubMenu = thisOne.getList(stringIDToTypeID("submenu"));
for (var n = 0; n < thisSubMenu.count; n++) {
var theTitle = thisSubMenu.getObjectValue(n).getString(stringIDToTypeID("title"));
// the guides show setting;
if (theTitle == "Guides") {
var checked = thisSubMenu.getObjectValue(n).getBoolean(stringIDToTypeID("checked"));
if (checked == true) {alert ("guides visible")}
else {alert ("guides invisible")}
}
}
}
};

 

Translate
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 ,
Jan 27, 2025 Jan 27, 2025

@c.pfaffenbichler Thanks for your script 🙂
Here is a version I was able to test with. Indeed, the setting are not updated immediately. But it could still help me.

function showGuidesVisibility() { // determine guides visibility;
	// 2025, use it at your own risk;
	
	if ($.locale == "fr_FR") { // localization
		var menuStr = "Affichage";
		var menuItemStr = "Afficher";
		var guidesStr = "Repères";
	}else{
		var menuStr = "View";
		var menuItemStr = "Show";
		var guidesStr = "Guides";
	}
	
	var resultStr = "unknow";
	var view_submenus = [];
	
	var r = new ActionReference();
	r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
	r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
	var temp = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu"));
	for (var m = 0; m < temp.count; m++) {
		var thisOne = temp.getObjectValue(m);
		// get window menu;
		if (thisOne.getString(stringIDToTypeID("title")) == menuStr) {
			view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(m).getList(stringIDToTypeID("submenu"));
			break;
		}
	}
	// get show menu;
	for (var m = 0; m < view_submenus.count; m++) {
		var thisOne = view_submenus.getObjectValue(m);
		if (thisOne.getString(stringIDToTypeID("title")) == menuItemStr) {
			var thisSubMenu = thisOne.getList(stringIDToTypeID("submenu"));
			for (var n = 0; n < thisSubMenu.count; n++) {
				var theTitle = thisSubMenu.getObjectValue(n).getString(stringIDToTypeID("title"));
				// the guides show setting;
				if (theTitle == guidesStr) {
					var checked = thisSubMenu.getObjectValue(n).getBoolean(stringIDToTypeID("checked"));
					resultStr = (checked)? "visible" : "invisible";
					break;
				}
			}
		}
	}
	
	alert("Guides visibility: " + resultStr);
}
Translate
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 ,
Jan 27, 2025 Jan 27, 2025
LATEST

I haven’t been able to figure out what forces an update of the menu setting the script evaluates; sometimes creating a new Layer and deleting it seems to suffice, sometimes not … 

Translate
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