Check if Menu item is enable or disabled

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Mcquiff

Check if Menu item is enable or disabled

Post by Mcquiff »

I would like to know if it is possible to check the status of a menu item in Photoshop. Specifically to check whether the View>Snap is ticked?

Many Thanks
User avatar
Kukurykus
Posts: 528
Joined: Mon Jul 25, 2016 12:36 pm

Re: Check if Menu item is enable or disabled

Post by Kukurykus »

There is a trick, but I know it's possible to do it profesionally what I don't know how at the moment.

Let's assume you always snap to (some or all): guides, slices, layer bounds and document bounds but never to grid then you can do that using my tricky method.

You certainly bound some function key of your action to the script I'm providing. Then always playing it the script saying to you is snap on/off.

When snap is on then grid is on too, but what is nice is that you never know grid is on or off, so if you don't need/use/like it, it won't disturb you.

Simply go to File / Edit / Preferences / Guides, Grid & Slices and you set in the Grid section:

- 'color' to GREY (128,128,128), as in most cases this one won't be visible on other colours
- 'style' to DOTS, as they are less visible than (dashes)lines
- 'gridline every' 1000 cm (you could use also inches, picas or points, but by lower number not px or %)
- 'subdivisions' 1 (it - and above setting - minimalize occurance you'll see a grid ever)

These settings could be set via script, but it's so easy I hope you do it yourself, though this part isn't needed if you set it manually once for keeps.


And the main rule how my script will be working: always when grid (you possibly never see) is ON, snap is ON too, and when OFF, 2nd is OFF too.
You simply press some function key and the alert inform you is it ON or OFF.

Code: Select all


$.level = 0 // you may delete it as long as you don't test it in ESTK
function snp(v) {
var id1 = charIDToTypeID( "slct" );
var desc1 = new ActionDescriptor();
var id2 = charIDToTypeID( "null" );
var ref1 = new ActionReference();
var id3 = charIDToTypeID( "Mn " );
var id4 = charIDToTypeID( "MnIt" );
var id5 = stringIDToTypeID( v );
ref1.putEnumerated( id3, id4, id5 );
desc1.putReference( id2, ref1 );
executeAction( id1, desc1, DialogModes.NO );
}

try{snp(n = "snapToGrid"), snp(n), alert('ON')} catch(err) {alert('OFF')}

Just remember (because you probably had some key bound to snap) add aditional line to your code or step to action where beside ticking on/off a snap, it will be doing the same with View / Show / Grid. This way only then launched script basing on grid presence tell you about snap activity.


EDIT: That would be okey, but I tested it now and unfortunately grid works in this case like document bounds. But I checked that if you do the same with slices instead of grid all will be fine.


Anyway I found even something smarter, however I'm not sure that won't be anoying for you, but at least you don't need to check by pressing any kay is snap ON or OFF.

Simply set in your action or script together with (un)ticking snap, View/Show/Layer Edges. When they're visible snap is ON, if not, then OFF :)