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();
})();