Question: is it possible to have extensions without a UI, or with an optional UI? I've managed to come close to getting this to work, but it seems to remain just beyond my grasp. This is using InDesign.

What I want to achieve:I want the extension to run at all times so it can listen for documentAfterSave events even when the panel is not showing, and I want to have the 'panel visible' state persist across user sessions.

The first thing was to get the extension to load on app startup.

In the Lifecycle panel in the manifest editor, I unchecked 'AutoVisible' (not sure whether that was important)

Then I added the applicationActivate event to the list of 'StartOn' events.

That makes my extension shows up when the app starts. Cool.

But I want to be in control of the panel visibility - i.e. if the user had the panel hidden when he last used the app, I want the extension to be hidden when the user launches the app at a later time.

I.e. I want to save the 'visible' state for the extension panel between user sessions. I tried saving and restoring the visible state via the CSXSInterface.instance.whatchamacallit stuff, and I tried listening for state change events for WINDOW_SHOW and WINDOW_HIDE, so I could keep track and safeguard the panel's visibility state, but it looks like those events don't really work (see Harb's bug list elsewhere on this forum). I also tried moving the panel off-screen to simulate being hidden (old trick, didn't work).

Before I give up and try a different approach (without extension builder), does anyone know whether this can be made to work?

Another lingering doubt: suppose I got it to work, how good is the documentAfterSave event? For example, when the user closes an unsaved document, and then agrees to save the document when alerted ('Do you want to save...' dialog).

Will the event fire early enough so I can still extract information from the document before InDesign starts tearing down the document data structures? Or will I end up in the twilight zone, where merely accessing the half-disassembled document object can cause crashes? Or will I find the document has already been closed from before the event fired?

AutoVisible=false means that when this extension is loaded its UI is not made visible, leaving that up to the extension. Generally, panels should have AutoVisible=true so that when a user selects the panel from the menu they can be assured that it will be made visible immediately, it also ensures correct behavior when the panel is docked or closed.

So the question is how to fix your problem?

I would suggest breaking this into two extensions, one extension that is a vanilla panel and another modeless extension which is hidden and sits waiting for events. The hidden one should start on applicationActivate, have AutoVisible=false, and not have a <Menu> element in its manifest (so it doesn't show up in Window > Extensions). This hidden extension can then respond to the save event, it can also activate your panel on first launch.

Great stuff! Zak, that sounds like a viable solution; I've already got a clean separation of responsibilities in my code, with well-defined interfaces and event-driven data exchange, so I have good hope I can separate things out fairly easily. As far as I think I can handle it, I'll put the 'datamodel' in the background extension, the 'view' in the foreground extension, and a 'controller' in both to take care of the communication between the two. The two controllers would exchange stuff via CSXSEvents.

Harbs, thanks for the little trick - that'll come in handy too at some point in tim, I am sure.

Cool! That would make it even easier. I'll probably need some CSXSEvents (the whole project is asynchronous and event driven by nature, and the 'background' controller would need to be able to report asynchronous things happening to the 'foreground' controller), but having the foreground controller directly call public methods in the background controller in the other extension makes things easier. Great stuff. Thanks so much!

A couple questions on how to have an invisible ui. Are there any update for getting this to work in 3.0?

It seems like AutoVisible=false doesn't work when using a CSExtension, but does when using mx.core.Application. Everything else seems to work find with mx:Application, except for being able to clean up. I have a server socket I need to close for Photoshop to exit cleanly, but I can't find any hook that'll let me both have an invisible extension and have a chance to cleanup.

I've tried going through PSEventAdapter, and various events on the Application, but haven't found anything yet.