File link and spaces in name of file


#1

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?


#2

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

#3

I tried that and it didn’t work.


#4

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

#5

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


#6

yeah, thank you works great!


Still No File Lauching
#7

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)


#8

Complexpoint,

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


#9

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

#10

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.


#11

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.