Skip to main content
Inspiring
June 22, 2023
Answered

Getting snap status

  • June 22, 2023
  • 3 replies
  • 1567 views

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

 

 

This topic has been closed for replies.
Correct answer r-bin
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);

 

3 replies

Inspiring
February 8, 2024

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?

c.pfaffenbichler
Community Expert
Community Expert
February 8, 2024

@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. 

Inspiring
June 24, 2023

Nomi30640303ex9q, you know that 

getEnumerationValue

is not a function, right?

Legend
June 23, 2023

Are you a bot ? : )

Inspiring
June 24, 2023

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?