Copy link to clipboard
Copied
I can toggle Photoshop's snap on and off with a script (View menu > Snap):
if (documents.length >0 )app.runMenuItem (stringIDToTypeID("snap"));
else alert("No documents, no snap.");
I've tried assigning a variable to runMenuItem but is undefined.
How do I get the (boolean) state of the snap? ie alert(snapStatus); // true
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var view_submenus = executeActionGet(r).getObje
...
Copy link to clipboard
Copied
Are you a bot ? : )
Copy link to clipboard
Copied
Yes, clearly I'm a AI fueled toaster techno robot from the future sent back in time to discover the secrets of snapping to layers in Photoshop to undermine humanity. Would you like to know more?
Copy link to clipboard
Copied
Yes, clearly I'm a AI fueled toaster techno robot from the future sent back in time to discover the secrets of snapping to layers in Photoshop to undermine humanity. Would you like to know more?
By @Ghoul Fool
Copy link to clipboard
Copied
Nomi30640303ex9q, you know that
getEnumerationValue
is not a function, right?
Copy link to clipboard
Copied
Let's try this again...
...Apart from being derailed by bots or manually setting the status is it possible to get the current state of snap & smart guides from AM code?
Copy link to clipboard
Copied
@Kukurykus posted a work-around a while back.
https://www.ps-scripts.com/viewtopic.php?p=152332&hilit=snap
I know of no better method so far.
Copy link to clipboard
Copied
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(9).getList(stringIDToTypeID("submenu"));
var snap = !view_submenus.getObjectValue(20).getBoolean(stringIDToTypeID("checked"));
alert("Snap="+snap);
Copy link to clipboard
Copied
Superneat!
On Photoshop 2024 20 on the list seems to be »rulers« and »snap« is 21 on the list. (They must have added a command since 2020.)
And the exclamation mark seems unnecessary.
Copy link to clipboard
Copied
@r-bin , I tried to amend your great code to work out for Photoshop 2024.
var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(9).getList(stringIDToTypeID("submenu"));
var theResults = new Array;
for (var m = 0; m < view_submenus.count; m++) {
var thisOne = view_submenus.getObjectValue(m);
if (thisOne.getString(stringIDToTypeID("name")) == "Snap") {
var snap = view_submenus.getObjectValue(m).getBoolean(stringIDToTypeID("checked"));
}
};
alert("Snap="+snap);
(edited)
Copy link to clipboard
Copied
@r-bin , I tried to amend your great code to work out for Photoshop 2024.
By @c.pfaffenbichler
maybe
var snap = view_submenus.getObjectValue(m).getBoolean(stringIDToTypeID("checked"));
)
Copy link to clipboard
Copied
Thanks, I edited the code in the post!
Copy link to clipboard
Copied
You mayhave been outputting code for your own sanity but
var theResults = new Array;
Doesn't get used.
Copy link to clipboard
Copied
But is the »Snap=…«-alert get raised?
Copy link to clipboard
Copied
Sorry, should have been more specific: I get the following error:
Error 8500: The requested property does not exist.
Line 8
-> if (thisOne.getString(stringIDToTypeID("name")) == "Snap") {
- So it doesn't even make it to the alert.
Copy link to clipboard
Copied
If you want to troubleshoot the issue you could try running this to see if you get any meaningful data from the menu items.
// 2024, 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 view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(9).getList(stringIDToTypeID("submenu"));
var theResults = new Array;
for (var m = 0; m < view_submenus.count; m++) {
var thisOne = view_submenus.getObjectValue(m);
checkDesc2(thisOne, true);
if (thisOne.hasKey(stringIDToTypeID("name"))) {
if (thisOne.getString(stringIDToTypeID("name")) == "Snap") {
var snap = view_submenus.getObjectValue(m).getBoolean(stringIDToTypeID("checked"));
}
}
};
alert("Snap="+snap);
////////////////////////////////////
////// based on code by michael l hale //////
function checkDesc2 (theDesc, theAlert) {
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';
};
if (theAlert == true) {alert("desc\n\n"+str);
return};
return 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
Thanks for that, c.pfaffenbichler!
Looks as though I still need help from a grown-up
The snap values is when M == 17, i == 4; but it seems to report it being enabled as true regardless of when it's on or off. So might not have the correct values.
See screenshot
Copy link to clipboard
Copied
I don’t have access to Photoshop 19, so I can't test.
I suspect »name« may have been introduced later for those objects.
How did you make sure that 14 and 4 is the right one if it doesn’t give the right result?
Copy link to clipboard
Copied
Looks like the only "word" it understands is "KIND". - I threw a list of four letter words at it! - Which sounds ruder that it was :D.
Copy link to clipboard
Copied
I found a running installation of Photoshop CC 2019 and, indeed, there »enabled« seems to be given as »true« no matter what for me, too.
// 2024, 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);
if (thisOne.getString(stringIDToTypeID("title")) == "View") {
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(m).getList(stringIDToTypeID("submenu"));
}
};
for (var m = 0; m < view_submenus.count; m++) {
var thisOne = view_submenus.getObjectValue(m);
if (thisOne.getString(stringIDToTypeID("title")) == "Snap") {
var snap = view_submenus.getObjectValue(m).getBoolean(stringIDToTypeID("enabled"));
}
};
alert("Snap="+snap);
Copy link to clipboard
Copied
I am afraid the »checked«-property was introduced after that version, so in that Photoshop-version this approach is not applicable.
Copy link to clipboard
Copied
I had to set the value from 9 to 10:
var view_submenus = executeActionGet(r).getObjectValue(stringIDToTypeID("menuBarInfo")).getList(stringIDToTypeID("submenu")).getObjectValue(10).getList(stringIDToTypeID("submenu"));
for version 2024 to return true.
Copy link to clipboard
Copied
Works in PS2020, sadly, doesn't work on older versions like 19. 😞