31148

How to get a hyperlink on a web page to open a file in a text editor (Sublime Text)

<h3>Question</h3>

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?


<h3>Answer1:</h3>

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


<h3>Answer2:</h3>

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


<h3>Answer3:</h3>

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

来源:https://stackoverflow.com/questions/36001941/how-to-get-a-hyperlink-on-a-web-page-to-open-a-file-in-a-text-editor-sublime-te

Recommend

  • How to appropriately include schemalocation to refer a xsd file in xml
  • spring security client_credentials grant_type - support for refresh token
  • Memory Leak UITableView
  • Close expandable ListView on child click
  • Sorting list of dictionaries according to specific order
  • type “e” does not exist , Redshift through Postgresql connector in php codeigniter
  • Convert HEX to ASCII, data from GPS tracker
  • Memory placements of C-function
  • How to do handle login-logoff
  • import cv2 doesn't give error on command-Prompt but error on IDLE on Windows 10, Python 3.6.4
  • Java: How to refer to subclass's static variable in abstract class?
  • How to use grep to output unique lines of code from a file?
  • performance counter events associated with false sharing
  • C++ Time measurement of functions
  • C, fread binary from bin file
  • Find string between two substrings AND between string and the end of file
  • Redmine can't generate secret token
  • Adding custom message on Thank You page by shipping method
  • Get an image from the video
  • Laravel 5.7: Custom blade template for Maintenance Mode but not 503.blade.php
  • Gitlab: copy project to other git lab repository
  • async GET request with body from browser
  • Map Annotation Disclosure Indicator - Xamarin.Form
  • Adding Dynamic Row and Data on Checkbox Click
  • Find all parks for a given zipcode with google maps
  • Admob in ListView not clickable
  • how to add dashed border on highcharts “area” graph for every point
  • How to use Typescript with libraries like Ampersand.js that parse configs to build prototypes
  • JavaMail connection problems [duplicate]
  • Magento-Change Attribute of All Products
  • Getting the type of a “Type” in C# reflection
  • Using redis as an LRU cache for postgres
  • How to warp text around image in iOS?
  • Spring Boot fails to start
  • Background transfer download task failed when app was closed
  • ssh remote server login script