Skip navigation
Currently Being Moderated

Accessing Photoshop object model from event listeners

Aug 10, 2010 7:37 AM

I need to solve a very basic problem - I need to know which document is currently selected in Photoshop at any given time.
There are a number of ways to do this, namely:
1) Subscribe for Photoshop events using CSXSInterface(i.e. using CSXSInterface::addEventListener) and then, in the event handler, access the active document property using CSAW object model (i.e.
2) Subscribe for PS events using ExtendScript interface(i.e. evalScript("PhotoshopRegisterEvent")) and then, in the event handler, access the Photoshop object model using the ExtendScript interface (by calling from ExtendScript).
3)  Subscribe for Photoshop events using CSXSInterface(i.e. using CSXSInterface::addEventListener) and then, in the event handler, access the Photoshop API using ActionDescriptors API (executeAction and executeActionGet APIs).

Unfortunately there is a major bug in Photoshop CS5 on Mac that makes Photoshop document model inaccessible from all OS-initiated event handlers. This bug seems to affect all the methods listed above. As a result, none of them works with Photoshop CS5 on Mac.


If I subscribe for CSXSInterface, I am able to access the activeDocument property of the com.adobe.photoshop.Application object, but the event comes in before the active document has changed, not after, so I cannot find out which document was selected.
I tried adding a timer in ActionScript and checking the active document a second after the event, but from the activeDocument property is not accessible from the timer handler.


If I try to use extendScript to access Photoshop DOM  inside an event handler, I get the following error: “Error: General Photoshop error occurred. This functionality may not be available in this version of Photoshop.”.
The same error occurs when I try to use executeActionGet API. I suspect that executeActionGet calls ExtendScript code under the hood, so I get the same result.


So, is there any way to use Photoshop API from an event listener on Mac CS5? Can some Adobe employee please comment on this situation?
Thank you in advance,
  • Currently Being Moderated
    Aug 10, 2010 1:08 PM   in reply to Anatoly Paraev



    Your timing is impeccable. We have managed to come up with a viable workaround for the PS Mac event issue. We literally have it ready as of today.


    I have attached both an SWC that contains the workaround and a sample project to show you how to use it.


    There are a couple of caveats -

    • This workaround has minimally tested. Use at your own risk. We have not stress tested at all.
    • Each time the workaround is invoked it requires roughly 0.02 seconds. While not significant by itself, they can add up, depending on how you use it.



    The sample project should be enough to show you how to use it.


    Feel free to post questions as they come up.






    Mark as:
  • Currently Being Moderated
    Aug 11, 2010 11:26 AM   in reply to Anatoly Paraev

    Your post confused me as I was seeing nothing like that here. I had a "versioning problem". The code on my Mac (where I did most of the testing) had one more (very important) line of code. Sorry. The attached library should fix the problem you're having with forceClean.


    As for what the workaround does:


    Ps DOM calls worked just fine when called from the context of a UI event. The only issue was when the event was a system-type event. What we were looking for was a way to end the event chain of the system event and yet continue executing the handler.


    Early on we found that you could execute a script using CSXSInterface.getInstance().evalScript - and that script could call PS DOM functions.


    The happy thought was to call into evalScript, to a script that used a HostObject to call back to ActionScript.





    Mark as:
  • Currently Being Moderated
    Jul 9, 2012 1:21 AM   in reply to Bob Stucky

    I'm just writing here to know if the PsMacDom project still open.....we have few problems with it....and i don't know where ask help....



    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points