File link and spaces in name of file

Using Preview version 170 on OS X 10.11.3

When I am creating a link to a file, the link only works properly if the filename contains no spaces (usually create this link by dragging the file from Finder/Path Finder). That is all the characters up to the first space are turned into a hyperlink, the rest is ignored.

Apologies if this not the correct terminology. The following image shows the effect of a file with and without spaces:

tested.taskpaper (887 Bytes)

Is this expected behaviour?

1 Like

I think so.

You need to precede the space in a filePath with a backslash.

( Try, for example, dragging a file from Finder.app into Terminal.app ā€“ this will create a version of the path in which spaces appear as '\ ā€™ )

/Users/houthakker/Desktop/Screen\ shot\ 2016-02-17\ at\ 00.14.04.png

I tried that and it didnā€™t work.

Ah ā€¦ é‚£ęˆ‘ä»¬å°±å¦å¤–ęƒ³åŠžę³•å§ ā€¦ :ā€“)

Jesseā€™s last note on this was, I believe, the one below, but it may refer to work in progress rather than the current build.

In the meanwhile you can already use url-encoded paths, in which the space is replaced by %20, for example:

"file:///Users/houthakker/Documents/Scanned%20Image%20160110000.pdf"

One way of getting a url-encoded path is to select one or more files in a Finder.app window, and copy encoded versions of their paths to the clipboard by running the following JavaScript for Automation script, either from Script Editor (Yosemite onwards) or from something like FastScripts or Keyboard Maestro.

ļ¼ˆNote, incidentally that if you have any non Anglo characters in the file name, they will also be encoded numerically, so for example, the file selected here,

might have a clickable encoded path in TaskPaper which looked something like:

file:///Users/houthakker/Desktop/Screen%20shot%20%E4%B8%87%E4%BA%8B%E9%80%9A%202016-02-17%20at%2000.14.04.png

(function () {
    'use strict';

    var a = Application.currentApplication(),
        sa = (a.includeStandardAdditions = true, a),

        strPaths = Application("Finder")
        .selection()
        .map(function (x) {
            return x.url();
        })
        .join('\n');

        sa.setTheClipboardTo(strPaths);

        return strPaths;
})();

Brilliant, Iā€™ve got that hooked up to a Keyboard Maestro hotkey now. :slight_smile: Thanks muchly!

1 Like

yeah, thank you works great!

1 Like

A Keyboard Maestro version for copying the encoded url(s) of the selected file(s) in Finder or CocoaTech PathFinder.

(For pasting as clickable links in TaskPaper 3)

Complexpoint,

Thank you for the JavaScript code as amended to included both Finder or Path Finder.

1 Like

The escape sequence depends on the link typeā€¦ if you are doing a URL link (file://ā€¦) then you need to escape spaces with %20. On the other hand if you are doing a ā€œTaskPaper magic recognize path linkā€ then you need to use \ to escape the spaces. For examples:

/Users/victor/Documents/scans/scan\ -\ 003.pdf
1 Like

Jesse,

Thank you for the information. I cannot seem to get the ā€˜TaskPaper magic recognise path linkā€™ method to work:

.

This occurs whether I copy the link into TaskPaper or type the link inside TaskPaper.

I think I just found the bug. Right now it only works if you escape one spaceā€¦ but if the path has more then one space it wonā€™t open the file and youā€™ll see that dialog. Iā€™ve just fixed for the next release.