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

Getting snap status

Engaged ,
Jun 22, 2023 Jun 22, 2023

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

 

 

TOPICS
Actions and scripting

Views

562

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

correct answers 1 Correct answer

People's Champ , Feb 08, 2024 Feb 08, 2024
This code is simplified and works 100% in PS2020.
It doesn't check menus by name, but uses fixed indexes. For other versions, a different sequence in the menu is possible. In this case, a more complex and universal code is needed.
 

 

var r = new ActionReference();
r.putProperty(stringIDToTypeID("property"), stringIDToTypeID("menuBarInfo"));
r.putEnumerated(stringIDToTypeID("application"), stringIDToTypeID("ordinal"), stringIDToTypeID("targetEnum"));

var view_submenus = executeActionGet(r).getObje
...

Votes

Translate

Translate
Adobe
People's Champ ,
Jun 23, 2023 Jun 23, 2023

Copy link to clipboard

Copied

Are you a bot ? : )

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 ,
Jun 24, 2023 Jun 24, 2023

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?

 

 

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
People's Champ ,
Jun 24, 2023 Jun 24, 2023

Copy link to clipboard

Copied

quote

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

 

It wasn't told to you.
 
 
 

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 ,
Jun 24, 2023 Jun 24, 2023

Copy link to clipboard

Copied

Nomi30640303ex9q, you know that 

getEnumerationValue

is not a function, right?

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 ,
Feb 08, 2024 Feb 08, 2024

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?

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 ,
Feb 08, 2024 Feb 08, 2024

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. 

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
People's Champ ,
Feb 08, 2024 Feb 08, 2024

Copy link to clipboard

Copied

This code is simplified and works 100% in PS2020.
It doesn't check menus by name, but uses fixed indexes. For other versions, a different sequence in the menu is possible. In this case, a more complex and universal code is needed.
 

 

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);

 

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 ,
Feb 08, 2024 Feb 08, 2024

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. 

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 ,
Feb 09, 2024 Feb 09, 2024

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)

 

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
People's Champ ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

quote

@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"));

 

)

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 ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

Thanks, I edited the code in the post! 

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 ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

You mayhave been outputting code for your own sanity but 

var theResults = new Array;

Doesn't get used.

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 ,
Feb 10, 2024 Feb 10, 2024

Copy link to clipboard

Copied

But is the »Snap=…«-alert get raised? 

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 ,
Feb 10, 2024 Feb 10, 2024

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.

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 ,
Feb 11, 2024 Feb 11, 2024

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;
};
};

 

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 ,
Feb 12, 2024 Feb 12, 2024

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

GhoulFool_2-1707732806958.png

 

 

 

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 ,
Feb 14, 2024 Feb 14, 2024

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? 

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 ,
Feb 15, 2024 Feb 15, 2024

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.

 

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 ,
Feb 15, 2024 Feb 15, 2024

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);

 

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 ,
Feb 15, 2024 Feb 15, 2024

Copy link to clipboard

Copied

LATEST

I am afraid the »checked«-property was introduced after that version, so in that Photoshop-version this approach is not applicable. 

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 ,
Feb 11, 2024 Feb 11, 2024

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.

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 ,
Feb 09, 2024 Feb 09, 2024

Copy link to clipboard

Copied

Works in PS2020, sadly, doesn't work on older versions like 19. 😞

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