Copy encoded url(s) of file(s) selected in Finder or Path Finder

Copy encoded URLs of selected files.kmmacros (20.1 KB)

For example, for pasting clickable links into TaskPaper 3

(function () {
    'use strict';

    var strFrontApp = Application("System Events")
            frontmost: true
        blnFinder = ["Finder", "Path Finder"].indexOf(strFrontApp) !== -1;

    if (blnFinder) {
        var app = Application(strFrontApp),
            lstSeln = app
            lstURL = (lstSeln && lstSeln.length) ? lstSeln
            .map(function (x) {
                return x.url();
            }) : [];

        if (lstURL.length) {
            var sa = (app.includeStandardAdditions = true, app),
                strUrls = lstURL.join('\n');

            return strUrls;



Thanks for sharing this script. It is very userful.

Iā€™d like to modify it to return a rich text hyperlink using the file name and URL.
I know how to create this from our previous work.

My question is, where/how to mod your code?
Iā€™m thinking in this block:

.map(function (x) {
   return x.url();

Instead of return x.url(), I could use my function and
return createRTFHyperlink(, x.url());

See anything wrong with that approach? Suggest otherwise?

Looks fine.

Thanks, Rob. Just what I was looking for.

1 Like

I am trying to use this but getting mixed results. I am using this to copy file links into OmniFocus, Mainly pdf files. Sometimes it works and the file will open in the Preview app and other times it just opens Finder and highlights the file? Can someone help as I would like the links to open with the default apps.

I've noticed that too ā€” in Mojave, file:/// URLs often just "reveal" the target file in the Finder instead of opening it. Not a big deal since you can then just āŒ˜O to open it, but still. Anyway, I'm pretty sure it's not a problem with the macro. Probably something to do with the new security features.

1 Like