Skip to main content
Legend
October 17, 2026
Question

How to achieve preventDefault in AIHostAdapter.aip

AIHostAdapter.aip is a plugin that captures events such as “when the selection has changed” in Illustrator’s CEP. It is reportedly included as a standard feature starting with version 30.3.

Since this plugin can capture events that occur before a menu command is executed, if it can cancel the command using `preventDefault` or similar methods, it should be possible to prevent situations such as a user accidentally trying to overwrite an opened .ai document as a non-editable .pdf.

How can `preventDefault` be implemented? If such functionality is implemented in the plugin, it should be possible to achieve this by notifying the plugin via `CSEvent` in `CSInterface`. Or is it impossible to stop the action once a `Notifier` has been issued, due to the SDK’s specifications?

3 replies

Participant
October 19, 2026

Thanks for sharing this approach. Even if preventDefault() isn’t supported for Illustrator commands, combining a custom export script with post-save checks could still provide a useful layer of protection against accidental overwrites. 😊

Translate
Community Expert
October 19, 2026

Interesting question.

From what I understand, there's a difference between detecting a command before it executes and actually preventing it from executing.

Illustrator's SDK supports Before and After command notifiers, including Save As, but I don't believe these provide a cancel mechanism equivalent to JavaScript's preventDefault().

I found an older discussion where someone was trying to disable Save and Save As through the SDK, and the conclusion was that although you could intercept the notification, you couldn't actually cancel the command.

https://community.adobe.com/questions-652/disabling-save-and-save-as-779823

I'm not sure whether anything has changed in more recent SDK versions, but I'd imagine passing a CSEvent back through CSInterface would only communicate with the plug-in, rather than interrupt Illustrator's own command execution.

For your PDF example, would using Save a Copy or Export as PDF be a better approach? That would preserve the original Illustrator document and avoid switching the active document to a PDF.

Or are you specifically trying to build a safeguard that prevents users from executing certain commands, regardless of how they're triggered?

Translate
sttk3Author
Legend
October 19, 2026

Good point. I don't know the exact inner workings of Illustrator either, but making event interrupts possible would probably require the software to be designed with that capability from the start. It might be difficult to achieve with a post-developed plugin.

Previously, to prevent unintended overwriting of ai files when exporting to pdf, I wrote a script to export pdfs using `exportForScreens` and replaced the export shortcut with that script (although saving copies is possible now). I was considering whether there was a way to build on that and create a safer workflow.

Even if the method mentioned in the title isn’t possible, it might be possible to compare the state of the file before and after saving, and if an operation matching a certain pattern is detected, display an alert or suggest using Undo.

Translate