Equivalent of tell application id("DNtp") in JavaScript

The preferred method to activate DT in AppleScript is
tell application id("DNtp")
because that works across all versions of DT. If I want to use JavaScript, there seems to be only
app = Application("DEVONthink 3")
to get an instance of the app – which is not exactly version-independent. Is there a way to use the bundle identifier (if that’s what DNtp is) in JavaScript?

It’s actually not the bundle identifier but the identifier of DEVONthink’s script suite and therefore independent of the used version/edition. But it doesn’t seem to be possible, see javascript automation - Calling an application by the bundle signature using JXA (macOS) - Stack Overflow

Thanks. I had seen that before but was hoping for more info here :wink:

If a script is intended to be run only from inside DT3, wouldn’t currentApplication be a robust alternative to Application(“DEVONthink 3”)?

At least inside of DEVONthink 3 this should work but not while developing it in the Script Editor.app.

Another incantation is:

Application('com.devon-technologies.think3')

(and the call to Application() is late-binding in JS, so you can construct application identifier strings at run time, if you want to).

Should your scripts emerge from pandemic lockdown in some future decade, and feel unsure about the current version name of DEVONthink, they could always obtain the name at run-time time, and pass that to Application()

(() => {
    'use strict';

    ObjC.import('AppKit');

    const
        ws = $.NSWorkspace.sharedWorkspace.runningApplications.js,
        candidates = ws.flatMap(x => {
            const name = x.localizedName.js;
            return name.startsWith('DEVONthink') ? (
                [name]
            ) : [];
        });

    return 0 < candidates.length ? (
        Application(candidates[0]).activate()
    ) : 'Nothing called DEVONthink seems to be running ...'
})();