skip to Main Content

Is there a way via extendscript (jsx) to get the visibility status of Photoshop’ guides?

The code to show and hide the guides is the same code as it ‘toggles’ the guides on or off so it must know the status when this code is executed, but how do I get at it?

I appreciate this could be done via a preference switch but that seems an awkward hack for something this simple, especially as something somewhere must be accessing this ‘property’ during execution of the ‘toggle’ code.

What would be great is to have activeDocument.guides.visible property, returning either true or false. Is there anything like that?

OK. Further investigation reveals that creating a guide using guides.add does not automatically toggle guides ON, however, using the code generated via the scriptListener does.

I would rather use guides.add as its only one line of code compared to fourteen so in order to toggle the guides to ON I thought I could run a function that created and then deleted a guide using the scriptListener code during the onLoad of the HTML.

This works great, except getting this function to run only when a document is opened is now the new problem.

documentAfterActivate is supposed to be the code to do this except it doesn’t work unless a flash panel such as kuler is opened first.

So the question now is really what part of the flash code is allowing documentAfterActivate to work properly and how can I use it in my code instead of opening a flash panel I don’t need?



  1. Chosen as BEST ANSWER

    The solution:

    As stated, the workaround is to create and delete a guide with the fourteen lines of code from the scriptListener. This toggles the guide visibility to ON regardless of its current state.

    I can then save this status as a preference using putCustomOptions.

    A function to do this is fired during the onLoad of the HTML but only when a document is opened otherwise guide creation fails.

    documentAfterActivate does not work as expected unless a further flash panel (such as Kuler) is also opened beforehand.

    An alternative to documentAfterActivate is to register the open event using CSevent instead.

    The code can be found HERE.

  2. It doesn’t look like you’ve got a direct toggle option. You’d need to record the position of the guides somewhere and use script listener code to clear them when you wanted to toggle them off and use the add method on the Guides object to re-add them.

    Keep in mind that even getting to the guide position via the photoshop DOM wasn’t avail before CS4 I think? maybe CS5.

    And i realised I just mis-read your question quite a bit. Anyway, this way you’d also know if the guides were visible based on whether or not they are there 🙂 But yes, it isn’t as nice as it could be.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top