Copy link to clipboard
Copied
Hello,
Is there a way to test in Javascript if document's guides are visible or not (shown or hidden by user)?
Thank you.
Copy link to clipboard
Copied
#target photoshop
if (app.documents.length > 0) {
var ref = new ActionReference();
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("guidesVisibility"));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
alert (docDesc.getBoolean(stringIDToTypeID("guidesVisibility")));
};
Copy link to clipboard
Copied
Thank you for your reply.
Unfortunately, line var docDesc = executeActionGet(ref); throws an error, telling this action isn't available.
Photoshop 13.0 (CS6) on Mac.
Copy link to clipboard
Copied
Quite frankly I am not going to install an obsolete Photoshop version to test this, but in 19.1.5 it works fine.
Does removing the line
ref.putProperty (stringIDToTypeID ("property"), stringIDToTypeID ("guidesVisibility"));
make a difference?
Could you post a screenshot of the Script in ESTK?
Copy link to clipboard
Copied
By the way it won't do job on CS6 EXTENDED too and with a case mentioned but is simplified to get submenus items, however prototype looks more complex now. Before you had to type .get(8).get(18).get(0) while now .get(8, 18, 0). It wouldn't work in CS6 EXTENDED too, but with generator in CC 2018 there is chance to use .getString(sTT('checked')). I hacked 'File / Generate / Image Assets' and I was able to use 'checked' with that item, but not with other submenus.
function sTT(v) {return stringIDToTypeID(v)}
(ref = new ActionReference()).putProperty(sTT('property'), sTT('menuBarInfo'))
ref.putEnumerated(sTT('application'), sTT('ordinal'), sTT('tergetEnum'))
Object.prototype.get = function() {
for(str = '', i = 0; i < arguments.length; i++) {
str += ".getList(sTT('submenu')).getObjectValue(arguments[" + i + "])"
}
return eval('this' + str)
}
executeActionGet(ref).getObjectValue(sTT('menuBarInfo')).get(8, 18, 0).getString(sTT('enabled'))
Copy link to clipboard
Copied
Does not work if the user turned off the guides through View-> Show-> Guides
P.S.. And Kukurykus, too
Copy link to clipboard
Copied
You’re right.
I had only tested with hiding them using cmd-H, apparently that did not do the issue justice.
Copy link to clipboard
Copied
True, I wrote originally 'in some specific case though', but then deleted it and went for more tests but forgot to repost that
Copy link to clipboard
Copied
Thanks all.
Maybe my Photoshop is too old, none of the posted scripts works
Copy link to clipboard
Copied
Can you run the below code and does it list »guidesVisibility« at all?
#target photoshop
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var docDesc = executeActionGet(ref);
checkDesc2(docDesc);
////// based on code by michael l hale //////
function checkDesc2 (theDesc) {
var c = theDesc.count;
var str = '';
for(var i=0;i<c;i++){ //enumerate descriptor's keys
str = str + 'Key '+i+' = '+typeIDToStringID(theDesc.getKey(i))+': '+theDesc.getType(theDesc.getKey(i))+'\n'+getValues (theDesc, i)+'\n';
};
alert("desc\n\n"+str);
};
////// check //////
function getValues (theDesc, theNumber) {
switch (theDesc.getType(theDesc.getKey(theNumber))) {
case DescValueType.ALIASTYPE:
return theDesc.getPath(theDesc.getKey(theNumber));
break;
case DescValueType.BOOLEANTYPE:
return theDesc.getBoolean(theDesc.getKey(theNumber));
break;
case DescValueType.CLASSTYPE:
return theDesc.getClass(theDesc.getKey(theNumber));
break;
case DescValueType.DOUBLETYPE:
return theDesc.getDouble(theDesc.getKey(theNumber));
break;
case DescValueType.ENUMERATEDTYPE:
return (typeIDToStringID(theDesc.getEnumerationValue(theDesc.getKey(theNumber)))+"_"+typeIDToStringID(theDesc.getEnumerationType(theDesc.getKey(theNumber))));
break;
case DescValueType.INTEGERTYPE:
return theDesc.getInteger(theDesc.getKey(theNumber));
break;
case DescValueType.LISTTYPE:
return theDesc.getList(theDesc.getKey(theNumber));
break;
case DescValueType.OBJECTTYPE:
return (theDesc.getObjectValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getObjectType(theDesc.getKey(theNumber))));
break;
case DescValueType.RAWTYPE:
return theDesc.getReference(theDesc.getData(theNumber));
break;
case DescValueType.REFERENCETYPE:
return theDesc.getReference(theDesc.getKey(theNumber));
break;
case DescValueType.STRINGTYPE:
return theDesc.getString(theDesc.getKey(theNumber));
break;
case DescValueType.UNITDOUBLE:
return (theDesc.getUnitDoubleValue(theDesc.getKey(theNumber))+"_"+typeIDToStringID(theDesc.getUnitDoubleType(theDesc.getKey(theNumber))));
break;
default:
break;
};
};
Copy link to clipboard
Copied
I tried your previous code that works in CC 2018. In CS6 EXTENDED that does't work indeed. Current one works of course
Copy link to clipboard
Copied
Another version for CC 2018:
function sTT(v) {return stringIDToTypeID(v)}
(ref = new ActionReference()).putProperty(sTT('property'), sTT('menuBarInfo'))
ref.putEnumerated(sTT('application'), sTT('ordinal'), sTT('tergetEnum'))
Object.prototype.get = function(v) {return this.getList(sTT('submenu')).getObjectValue(v)}
executeActionGet(ref).getObjectValue(sTT('menuBarInfo')).get(8).get(18).get(0).getString(sTT('enabled'))
Copy link to clipboard
Copied
And why do you need to know the guides are visible or not?
On CS6 it's impossible to know.
You can use the function to force the visibility of the guides.
Works in CS6 and CC2018.
show_guides()
function show_guides()
{
try {
var d1 = new ActionDescriptor();
var d2 = new ActionDescriptor();
d2.putUnitDouble( charIDToTypeID( "Pstn" ), charIDToTypeID( "#Prc" ), 200 );
d2.putEnumerated( charIDToTypeID( "Ornt" ), charIDToTypeID( "Ornt" ), charIDToTypeID( "Hrzn" ) );
d1.putObject( charIDToTypeID( "Nw " ), charIDToTypeID( "Gd " ), d2 );
executeAction( charIDToTypeID( "Mk " ), d1, DialogModes.NO );
app.activeDocument.guides[app.activeDocument.guides.length-1].remove();
}
catch (e) { alert(e); throw(e); }
}
Copy link to clipboard
Copied
c.pfaffenbichler, I have run your script but there is not guidesVisibility in the result.
r-bin, your function show_guides() works fine.
Considering the difficulty, I will modify my project. Anyhow, It wasn't an "essential" script.
Thank you very much for all your replies.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now