Access of activeDocument on a Mac

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

GuyOxford

Access of activeDocument on a Mac

Post by GuyOxford »

I am writing a Photoshop plug in in ActionScript 3.

I am having a very confusing and frustrating issue with app.activeDocument. My code works perfectly with Photoshop for Windows but on a Mac I get the "General Photoshop errooccurreded. This Functionality may not be available in this version of Photoshop." error.

To try and get to the root of the issue, I wrote a class just to get the document reference and called it from a test panel. The class call worked perfectly. I then included the same class in my main panel project and it breaks.

This is my class: -

Code: Select all    package DocRefGetter
    {
       import com.adobe.csawlib.photoshop.Photoshop;
       import com.adobe.photoshop.*;
       
       public class DocRefPhotoshop
       {
          
          public static function getDocRef():Document
          {
             var app:Application = Photoshop.app;
   
             var thisDoc:Document = app.activeDocument;
             //var thisDoc:Document = app.documents.index(0);  //Tried this method too
   
             return thisDoc;
             
          }
       }
    }

For the purpose of posting here, I have simplified things a little, i.e. I have removed things like the "try, catch" statements but essentially this is the code that does not work in the context of my panel. I also tried the equivalent call to JSX code with exactly the same result, worked perfectly for Windows, worked in a test panel on Mac, would not work in my main project on Mac.

As I said, inside a test, this works perfectly. Here is the test mxml code: -

Code: Select all    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" historyManagementEnabled="false">
       <mx:Script>
          <![CDATA[
             import DocRefGetter.DocRefPhotoshop;
             
             import com.adobe.photoshop.Document;
   
             [Bindable]
             private var hostName:String = HostObject.mainExtension;
             
             protected function button1_clickHandler(event:MouseEvent):void
             {
                var thisDocRef:Document = DocRefPhotoshop.getDocRef();
                testLabel.text = String(thisDocRef);
             }
             
          ]]>
       </mx:Script>
       <mx:VBox height="100%" width="100%" verticalAlign="middle" horizontalAlign="center">
          <mx:Button label="Run PS code" click="button1_clickHandler(event)" />
          <mx:Label id="testLabel" width="182" text="Label"/>
       </mx:VBox>
    </mx:Application>

I can't post the main application that it isn't working in as it is extremely large and complicated so what I am asking is has anyone come across a situation before where somehow something is conflicting with this type of document reference? I have been trying to resolve this for over a week now. I have tried many different solutions but nothing has worked. Mac Photoshop just simply doesn't want to see the open document.

Any suggestions are welcome but I am hoping most that someone has come across this exact situation before and has a precise solution.

Many thanks for taking the trouble to take a look at this.