How to link to file system to actually open a file?


Scrivener appears to support two kinds of links: internal to the current Scrivener project and external, to any Web address. It does not appear to support links to files on the Mac file system, however. For example, I added a link file:///Users/me/Documents/test.pdf. Clicking on that link does NOT open test.pdf, as I’d expected and as a program such as MacJournal does, but rather brings up the /Users/me/Documents folder in the Mac finder, with test.pdf selected. In other words, Scrivener can find the target specified in the URL but does not open it. Maybe this is because it does not know which file to use to open this PDF. Is there a way to tell Scrivener which application to use to open a file?


I’m afraid this was a change Apple made, I think back in Leopard. If you add file links to TextEdit, you’ll find they do exactly the same thing there, too. There’s no way of changing it, though I will look into it for 2.0. You can always add links to the research pane instead of course.

All the best,

Thanks for the quick reply, Keith. Just to clarify, this link was added in a document in the Research section as it points to some reference article. Also, if it’s an Apple thing, how is it that MacJournal gives me the desired behavior?

Forgot to add: just purchased my Scrivener license well before demo expired because it is already making my writing projects much easier. I’m recommending it widely! Keep up the great work. -B.

Presumably MacJournal overrides the default behaviour, which is what I will look at doing. I was talking about the default behaviour only - Apple changed it in the text system (all apps will differ when it comes to adding non-standard behaviour). Scrivener currently has no code of its own for dealing with web and file links - it just uses the standard Apple text system behaviour for such things (it only has its own code for Scrivener links). You can catch clicks on links though and change the default behaviour, which is most likely what MacJournal does. My guess is that Apple changed it to opening the Finder window so that you could choose which program to open the file in, rather than having to go through the default. As I say, I’ll look at it for 2.0, depending on time.
Thanks and all the best,

Why not just add the file as a document reference in the Inspector?


OK, that worked…I didn’t do this since I’m new to Scrivener and didn’t know about this yet.

Funny thing, though. When I drag the document to the reference pain the URL that it generates is
[file://localhost/Users/me/Documents/test.pdf](file://localhost/Users/me/Documents/test.pdf). Clicking on it in the reference pane opens the pdf, which is what I wanted. Pasting this URL into a document under research doesn’t though, just shows it in the finder as described. So some part of Scrivener already knows how to do what I was looking to do.


I think that you need to make your file a hyperlink, not a simple text object.

Also use 'file:///" instead of “file://localhost/”. The former works in textedit, the latter does not.

Yes, because as I said before, links in the text use the Apple default behaviour; links in the inspector are my own implementation. So not a funny thing at all…

Sorry, you did mention the Apple default behavior as the cause but I’m not familiar enough with how the inspector works to have known that this was a different implementation. Now it makes perfect sense, thanks.

Basically, links in the text (except for Scrivener links) are handled by the underlying text system; the links in the inspector references were coded by me. That’s why there’s a difference. To make the links in the text act the same, it’s just a matter of overriding the default text system behaviour to call the same code as the inspector does when you double-click on the link there. But yes, it’s definitely not obvious to the end-user because it’s a code/implementation detail; just one I hadn’t really thought about before. As I say, I’ve added it to the list of things to do, but although it is only an hour or two of coding, I have so much to do on 2.0 that it’s a little down the list.
Hope that makes sense.
Thanks and all the best,