Feasibility of Firing Custom Events from C++ Plugin and Listening in InDesign UXP Plugin

Hello UXP community,

I’m exploring a hybrid plugin approach for Adobe InDesign where we combine a C++ plug-in with a UXP plug-in.

Goal:
From the C++ plug-in, fire a custom event and have the UXP plug-in listen to it via app.addEventListener() in JavaScript.

Background:

  • In CEP, this was possible by dispatching events from C++ using the SDK and catching them in ExtendScript or JavaScript.

  • In UXP, I have successfully called commands and scripted actions, but I have not found documentation confirming whether custom events (not built-in InDesign events) can be dispatched from C++ and picked up in UXP.

  • UXP docs show app.addEventListener(eventName, handler) for built-in events, but it’s unclear if C++ → UXP custom events are supported.

Questions:

  1. Is it technically feasible to dispatch a custom event from a C++ plug-in and listen to it in a UXP plug-in?

  2. If yes, what would be the correct approach or API?

  3. Are there any limitations on event names, payloads, or event types that UXP can handle from the C++ side?

Any insights, examples, or documentation references would be greatly appreciated.

Thanks,
Niraj

This technique would be interesting for my team to use to migrate from ExtendScript to UXP. We’d like to get our customers using the UXP-based solution as it slowly gets developed. The ExtendScript-based solution is huge, and we don’t expect to have everything moved over to UXP for another year or so. If we had a way to send a request to ExtendScript, this could get us users sooner. Maybe there’s another way, but I wasn’t aware of any communication options between ExtendScript and UXP because our ExtendScript runs in its own engine.

jsw

If your ScriptInfo resource targets kUxpScriptMgrBoss instead of kJavaScriptMgrBoss, or directly kCoreScriptManagerBoss, the constants matching your event names should show at the supported class.

E.g. something similar to

alert(LayoutWindow.AFTER_ACTIVATE);

… assuming you have a working alert(), and using YOUR_EVENT_NAME …

Jon, yours is a different problem.

E.g. here a cheap shim for an UXP alert()

function alert()
{ app.doScript(“alert.apply(this,arguments)”,ScriptLanguage.JAVASCRIPT,[…arguments]); }

To specify the targetengine, use the same directive as always.

app.doScript(“#targetengine Jon\n alert($.engineName)”,ScriptLanguage.JAVASCRIPT);

1 Like

Thanks, @Dirk. I’ll give that #targetengine concept a test. That might help us out.

Jon

@Dirk That concept indeed worked great. Thanks!

Is there a known way to communicate from ExtendScript to a UXP-based plug-in?

And I don’t mean just the result of the .doScript but instead calling something in the UXP-based plug-in from our ExtendScript solution as needed from there.

Jon