3

I'm working on a large static website (Jekyll) and would like to be able to click on a link on a page in browser (Chrome) which will open it's corresponding source file on the local machine (Sublime). I can get the absolute link of the file.

From the console (Ubuntu) I can do:

subl path/to/file.txt

to open a file, so perhaps an extension that allows command execution on trusted domains?

3 Answers 3

2

Ubuntu There is a solution for Ubuntu

Windows Method

You first have to install a Protocol Handler in the Windows registry. (Reference: Custom protocol handler in chrome)

This will get Chrome to run a command when a subl:path/to/file link is clicked. But you can't simply run sublime_text.exe subl:path/to/file, because Sublime doesn't understand the subl:path/to/file parameter. You first have to extract the filename with a script and then call Sublime with a single file parameter.

Solution 1

This is a Solution for Windows, that opens links with the format

subl://open?url=file://<path_to_file>&line=4

It first registers a Script as a Protocol Handler, which in turn calls Sublime

Solution 2

I edited Solution 1 to open links in the format

subl://path/to/file:line

Just follow Solution 1, but change open_file.vbs to:

' path to sublime_text.exe
Dim sublime_path
' CHANGE THIS:
sublime_path = "C:\Programme\Sublime Text 3\sublime_text.exe" 

Dim text, filename
' get first command line argument
text = WScript.Arguments.Item(0)

filename  = Split(text, ":/")(1)

Dim run_command
run_command = """"&sublime_path&""" """&filename&""""

Dim objShell
Set objShell = WScript.CreateObject( "WScript.Shell" )
objShell.Run(run_command)
Set objShell = Nothing

(You have to change the path to your sublime_text.exe)

Mac https://github.com/corysimmons/subl-handler

1
  • For MacOS: I actually found this repo inopinatus/sublime_url to be more recently maintained than corysimmons/subl-handler
    – John Kacz
    Commented Jul 29, 2020 at 3:06
0

There's a Chrome extension, that let's you open a link with an external application: Open with external application

1
  • Sadly an old plugin, architecture no longer supported: screenshot
    – wjdp
    Commented Mar 15, 2016 at 17:40
-1

Old question, but you can try this: subl://path/to/file.txt

3
  • did you suggest this because you had reason to believe that it actually works? I have never heard of using subl:// in place of http:// and it didn't work when i tried it. If suggesting "you can try this" it would be good to provide link to a resource which explains why your suggestion should work (assuming you don't explain it yourself)
    – uglycoyote
    Commented Jan 31, 2019 at 6:32
  • I did find this in the xdebug documentation at : xdebug.org/docs/all_settings xdebug.file_link_format. So maybe you don't need to be so quick on downvotes. My mistake for not providing more info.... Commented Jan 31, 2019 at 10:17
  • I was not that quick to downvote, I actually tested your suggestion first and found that it did not work. But your reply has further confused me, as it is linking to documentation for an "XDEBUG EXTENSION FOR PHP", and the relevance of this to either hyperlink schemas, browser behaviour, or Sublime Text is still unclear. It's also still unclear whether your solution is something that worked for you (can you follow a subl:// hyperlink on your machine and have it open in Subilme Text directly?) or was your suggestion just something that you found in the doc and suggested blindly?
    – uglycoyote
    Commented Feb 4, 2019 at 20:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.