Skip to main content
Participant
December 23, 2022
Question

Intercept TextFrame deletion through a script

  • December 23, 2022
  • 3 replies
  • 2274 views

Hi all,
I have an Indesign document made up of various articles divided into several text frames. Through a script is it possible to intercept the deletion of any text frame?
Thanks for your help

This topic has been closed for replies.

3 replies

Inspiring
January 16, 2023

How about attaching an event to the menuAction?

#targetengine "session"
if (app.menus.itemByName("Main").submenus.itemByName("$ID/Edit").menuItems.itemByName("$ID/Clear").associatedMenuAction.eventListeners.itemByName("beforeInvokeClear").isValid) {
    app.menus.itemByName("Main").submenus.itemByName("$ID/Edit").menuItems.itemByName("$ID/Clear").associatedMenuAction.eventListeners.itemByName("beforeInvokeClear").remove();
}
app.menus.itemByName("Main").submenus.itemByName("$ID/Edit").menuItems.itemByName("$ID/Clear").associatedMenuAction.addEventListener(
    MenuAction.BEFORE_INVOKE, function(myEvent) {
        for (var i = 0; app.activeDocument.selection.length > i ; i++) {
            if (app.activeDocument.selection[i] instanceof TextFrame) {
                alert("Please do not delete the text frame.");
                myEvent.preventDefault();
                break;
            }
        }
    }).name = "beforeInvokeClear";
Community Expert
January 17, 2023

Hi @琥珀 猫太郎,

Won't that work only when the deletion is triggered by the menu option. What happens when the user uses the delete key. Frankly speaking I never used the Clear menu untill today after looking at your code.

-Manan

-Manan
Inspiring
January 17, 2023

I think that the shortcut of Clear menu is applied to DEL Key.

Robert at ID-Tasker
Legend
December 23, 2022

Are you talking about an event - the moment user hits Delete key - or checking during next opening of the file for missing objects ? 

 

Participant
December 27, 2022

Thanks for the reply,
what I have to do is intercept the deletion of the TextFrame to show a warning message.
Do you think there is a way to do this through a script?
Thanks again

Community Expert
December 27, 2022

Hi @lo22764185qzp2 ,

should this work on your machine or should it work on the machine from someone else?

As I already said: If its your machine you can do something.

To make it more clear: You cannot provide a document where this warning mechanism is embedded.

 

Regards,
Uwe Laubender
( Adobe Community Expert )

Community Expert
December 23, 2022

Hi @lo22764185qzp2 ,

there is nothing you can do if you make the document available to someone else who is not working on your machine with your version of InDesign.

 

Theoretically one  could install a startup script with an event handling mechanism that can detect the document and a list of text frames identified by their IDs. But a clever user can work around this by exporting the document to IDML and open the IDML file as new document…

 

What you can do is lock items like text frames.

Text is still editable if InDesign's preferences are set to allow the selection of locked items.

But this is not a document specific preference:

 

Preferences > General > Object Editing

[  ] Prevent Selection of Locked Objects

 

Regards,
Uwe Laubender
( Adobe Community Expert )

brian_p_dts
Community Expert
Community Expert
December 24, 2022

Easier yet, just lock the layer the text frames are on.