Skip to main content
Inspiring
Jun 30, 2026 7:12 AM UTC
Answered

UXP: How to create an instance of a class from included js-file?

I’ve written in ExtendScript the include part like this:


In the file ec_general_DEV.jsx, which is the file to be included:

function general (g){
    this.g = g;
    this.remove_trailing_linefeeds = function (str){ // general_class
        while (str.slice(-1).charCodeAt() == 10 || str.slice(-1).charCodeAt() == 13) str = str.slice(0, -1);
        return str;
    }


... and in the file which is including the ec_general_DEV.jsx:

#target indesign;
#include '/Library/Scripts/Adobe Automation/ec_general_DEV.jsx';
g = {}
INST_gene = new general (g); // New instance
// Example of usage
general_txt = INST_gene.remove_trailing_linefeeds (g.source_PI.rows[39].cells[1].contents) + '\r';


And I'm trying to make it work in UXP environment.

//@include '/Library/Scripts/Adobe Automation/ec_general_DEV.jsx';

 

Many thanks in advance!

Cheers!

Funtom

 

    Eugene TysonCorrect answer
    Community Expert
    Jun 30, 2026 8:16 AM UTC

    Hey, how’s it going.
     

    UXP does not support ExtendScript preprocessor includes such as:

    #include
    //@include

    So the usual approach is to turn the included file into a normal JavaScript module and load it with require() or import, depending on how your UXP project is set up.

    // ec_general_DEV.js

    class General {
        constructor(g) {
            this.g = g;
        }

        remove_trailing_linefeeds(str) {
            return String(str).replace(/[\r\n]+$/, "");
        }
    }

    module.exports = General;


    Main UXP

    const General = require("./ec_general_DEV.js");

    const g = {};
    const INST_gene = new General(g);

    const general_txt =
        INST_gene.remove_trailing_linefeeds(g.source_PI.rows[39].cells[1].contents) + "\r";


    Also, these are ExtendScript-only, so they will not work the same way in UXP

    #target indesign
    #include
    //@include

    UXP files should generally be .js rather than .jsx, and the module should usually reference relatively from inside the UXP plugin/script folder

    require("./ec_general_DEV.js");

    rather than from an absolute system path such as:

    /Library/Scripts/Adobe Automation/ec_general_DEV.jsx

     

    2 replies

    FuntomAuthor
    Inspiring
    Jun 30, 2026 9:02 AM UTC

    Great many thanks!

    Translate
    Eugene TysonCommunity ExpertCorrect answer
    Community Expert
    Jun 30, 2026 8:16 AM UTC

    Hey, how’s it going.
     

    UXP does not support ExtendScript preprocessor includes such as:

    #include
    //@include

    So the usual approach is to turn the included file into a normal JavaScript module and load it with require() or import, depending on how your UXP project is set up.

    // ec_general_DEV.js

    class General {
        constructor(g) {
            this.g = g;
        }

        remove_trailing_linefeeds(str) {
            return String(str).replace(/[\r\n]+$/, "");
        }
    }

    module.exports = General;


    Main UXP

    const General = require("./ec_general_DEV.js");

    const g = {};
    const INST_gene = new General(g);

    const general_txt =
        INST_gene.remove_trailing_linefeeds(g.source_PI.rows[39].cells[1].contents) + "\r";


    Also, these are ExtendScript-only, so they will not work the same way in UXP

    #target indesign
    #include
    //@include

    UXP files should generally be .js rather than .jsx, and the module should usually reference relatively from inside the UXP plugin/script folder

    require("./ec_general_DEV.js");

    rather than from an absolute system path such as:

    /Library/Scripts/Adobe Automation/ec_general_DEV.jsx

     

    Translate