4 Replies Latest reply: Feb 3, 2012 8:44 AM by Manan Joshi RSS

    How to get notified when InDesign Application hides (Mac)

    rafx79 Community Member

      Hi!

       

      I need to modify the behavior of a secondary process  I launch in my plugin when the InDesign app hides (from the dock or using the cmd+h key combination).

      I was trying to add an observer and callback using the Notification Center (local) though I can't find a way to get the main or key window to do so.

       

      Anyone has any pointers as how I can do this?

       

      Thanks!

        • 1. Re: How to get notified when InDesign Application hides (Mac)
          Dirk Becker Community Member

          I'm not sure what you mean with Notification Center (local).

          Sounds like an OSX specific thing.

           

          Instead, attach an InDesign IObserver to the kAppBoss, protocol IID_IAPPLICATION.

          You'll receive kApplicationSuspendMsg and kApplicationResumeMsg.

           

          Hth,

          Dirk

          • 2. Re: How to get notified when InDesign Application hides (Mac)
            rafx79 Community Member

            I only receive the kApplicationSuspendMsg (InDesign CS3), what could I be missing?

             

            In the startupshutdown i have:

             

            obsv = (IObserver*) CreateObject (kAppObserverBoss, IID_IOBSERVER);

            //attach app messages observer

            InterfacePtr<IApplication> iApp (gSession->QueryApplication ());

            InterfacePtr<ISubject> iAppSubject (iApp, IID_ISUBJECT);

            if(iAppSubject)

                      iAppSubject->AttachObserver(obsv , IID_IAPPLICATION);

             

            and in the update of the appObserver I have:

             

             

            do {

                                if( theChange.Get ()== kAppBoss)

                                {

                                          if(protocol.Get()==IID_IAPPLICATION){

                               if(theChange==kApplicationSuspendMsg){

                                                                   fprintf(stderr, "kApplicationSuspendMsg\n");

                               }

             

                                                    if(theChange==kApplicationResumeMsg){

                                                              fprintf(stderr, "kApplicationResumeMsg\n");                  

                                                    }

                                          }

                                }

            }while(kFalse);

            • 3. Re: How to get notified when InDesign Application hides (Mac)
              rafx79 Community Member

              I have another problem, I think what I need instead is to make my secondary process (with gUI) nest as a child window to indesign's main window, because if I try to use this messages, I'll always receive them when I change focus to the separate window.

              • 4. Re: How to get notified when InDesign Application hides (Mac)
                Manan Joshi Community Member

                As Dirk rightly pointed out, you need to place an observer in the kAppBoss and observe on the IID_IAPPLICATION protocol.

                 

                What you should do is just place an interface as an addin in the kAppBoss and give it an implementation (you don't need to create a observer boss class as you have done).

                 

                In startup call the autoattach of your observer, for ex

                  InterfacePtr<IApplication> app(gSession->QueryApplication());

                 

                  InterfacePtr<IObserver> iMyObserver(app, IID_IMYOBSERVER);

                                    iMyObserver->AutoAttach();

                 

                In the autoattach method of your implementation class, remember to pass your observers interface ID to the attachobsever method of the ISubject

                for ex

                AttachObserver(this, IID_IAPPLICATION, IID_IMYPOBSERVER);

                 

                Then in the update method you will get properly notified of the suspend and resume of application

                 

                This should fix your problem.

                 

                Manan Joshi

                 

                - Efficient InDesign Solutions -

                MetaDesign Solutions

                http://metadesignsolutions.com/services/indesign-development.php