Skip to main content
Inspiring
January 26, 2025
Question

Photoshop extendscript guides visibility?

  • January 26, 2025
  • 2 replies
  • 427 views

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?

 

2 replies

c.pfaffenbichler
Community Expert
Community Expert
January 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")}
}
}
}
};

 

frmorelAuthor
Inspiring
January 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);
}
c.pfaffenbichler
Community Expert
Community Expert
January 27, 2025

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 … 

Stephen Marsh
Community Expert
Community Expert
January 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.

c.pfaffenbichler
Community Expert
Community Expert
January 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.