Indesign Scripting - BehaviorEvents.MOUSE_EXIT

Community Beginner ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

Hi all, I have a question regarding BehaviorEvents.MOUSE_EXIT and BehaviorEvents.MOUSE_ENTER. Is it possible to remove them all using javascript? If this is possible, how do I do this as a newbie?

TOPICS
Scripting

Views

71

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Dec 13, 2021 Dec 13, 2021

Hi David, what you're asking is probably possible, but we'd need more information about your specific needs.

To get started, here's a script I just wrote that will remove behaviors with those event types from all buttons in the active document. I've made it fairly flexible so behaviors can be removed from other items and target different events. Let me know if that works for you.

- Mark

 

/*
    Remove Behaviors
    for Adobe Indesign 2022

    by m1b
    here: https://community.adobe.com/t5/indesig
...

Likes

Translate

Translate
Adobe Community Professional ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

What do you mean by 'removing them all'? Remove what? From where?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Dec 14, 2021 Dec 14, 2021

Copy link to clipboard

Copied

LATEST

You are, of course, absolutely right. Sometimes you have the problem in your head and forget that everyone else has not been included in your thoughts so far. I think m1b's answer contains exactly what I was looking for. But he too actually had to guess wildly at my needs.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Dec 13, 2021 Dec 13, 2021

Copy link to clipboard

Copied

Hi David, what you're asking is probably possible, but we'd need more information about your specific needs.

To get started, here's a script I just wrote that will remove behaviors with those event types from all buttons in the active document. I've made it fairly flexible so behaviors can be removed from other items and target different events. Let me know if that works for you.

- Mark

 

/*
    Remove Behaviors
    for Adobe Indesign 2022

    by m1b
    here: https://community.adobe.com/t5/indesign-discussions/indesign-scripting-behaviorevents-mouse-exit/m-p/12590473
*/


function main() {


    removeBehaviors(

        // remove behaviors from these items:
        app.activeDocument.buttons,

        // remove only behaviors triggered by these events
        [
            BehaviorEvents.MOUSE_ENTER,
            BehaviorEvents.MOUSE_EXIT
        ]

    );


    function removeBehaviors(items, targetEventTypes) {
        if (items == undefined) return;
        if (targetEventTypes == undefined) return;

        // iterate over items
        for (var i = 0; i < items.length; i++) {
            var item = items[i];
            if (!item.hasOwnProperty('behaviors')) continue;
            var behaviors = item.behaviors;

            // iterate over item's behaviors
            behaviorLoop:
            for (var b = behaviors.length - 1; b >= 0; b--) {

                // iterate over array of behaviorEvents to remove
                for (var e = 0; e < targetEventTypes.length; e++) {
                    if (behaviors[b].behaviorEvent == targetEventTypes[e]) {
                        //$.writeln('removing "' + behaviors[b].name + '" behavior (' + targetEventTypes[e] + ') from item ' + i);
                        behaviors[b].remove();
                        continue behaviorLoop;
                    }

                }
            }
        }

    } // end removeBehaviors


} // end main

app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, 'Remove Button Behaviors');

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines