Get Address script for IntelliJ IDEA

Assuming the use of a file:// URL, something like this may work for a Get Address script which doesn’t need a parallel Get Name (it aims to fetch both).

Note that this script is written in JavaScript for Automation, so you need to keep the opening line: //JavaScript

JS Source
//JavaScript
(() => {
    'use strict';

    const main = () => {
        const
            procs = Application('System Events')
            .applicationProcesses.where({
                name: 'idea'
            });
        return 0 < procs.length ? (() => {
            const ws = procs.at(0).windows;
            return 0 < ws.length ? (() => {
                const
                    tpl = ws.at(0).name().split('['),
                    fp = tpl[1].slice(0, -1);
                return doesFileExist(fp) ? (
                    `[${tpl[0].trim()}](${
                        encodeURI('file://' + filePath(fp))
                    })`
                ) : ''
            })() : ''
        })() : '';
    };

    // GENERIC FUNCTIONS ----------------------------
    // https://github.com/RobTrew/prelude-jxa

    // doesFileExist :: FilePath -> IO Bool
    const doesFileExist = strPath => {
        const ref = Ref();
        return $.NSFileManager.defaultManager
            .fileExistsAtPathIsDirectory(
                $(strPath)
                .stringByStandardizingPath, ref
            ) && 1 !== ref[0];
    };

    // filePath :: String -> FilePath
    const filePath = s =>
        // The given file path with any tilde expanded
        // to the full user directory path.
        ObjC.unwrap(ObjC.wrap(s)
            .stringByStandardizingPath);

    // MAIN ---
    return main();
})();

1 Like

Depending on the exact .app name of the particular version of IntelliJ which you are running, an Open script in AppleScript could use the form:

do shell script "open -a 'IntelliJ IDEA CE.app' " & "$0"

which might expand, for example to a particular url like:

do shell script "open -a 'IntelliJ IDEA CE.app' file:///Users/houthakker/IdeaProjects/someKind.java"