Mikulas Dite
Mikulas Dite

Reputation: 7941

Open file in editor from browser, on Mac

I'd like to have a link which allows me to open a file in my favorite IDE. Textmate registeres it's own protocol txmt://open/?url=file://%file&line=%line and it works fine, but I can't find out how to open the file in some other application (for example NetBeans).

This probably requires registering some protocols and setting my browser - I'd like to register it on Chrome.

Upvotes: 4

Views: 534

Answers (3)

Nathan Redblur
Nathan Redblur

Reputation: 641

I recently have been working in rails and error pages was set by default to open with txmt, to fix that I get with this idea.

  1. download this wonderful tool https://github.com/johnste/finicky this is able to open certain pages in different browsers or rewrite domains for example.

  2. Edith the config, so we're going to rewrite txmt format to vscode format

module.exports = {
  rewrite: [
    {
      match: /^txmt:\/\/open\?url=file:\/\/(.*)/,
      url: ({ urlString }) => {
        const newPath =  urlString
          .replace("txmt://open?url=file://", "vscode://file/") 
          .replace("&line=", ":")
          .replace("&column=", ":")

        finicky.log(newPath)
        return newPath
      }
    },
  ],
  handlers: [
    {
      match: /^vscode:\/\/(.*)/,
      browser: "Visual Studio Code"
    }
  ]
}

  1. now we need to link any txmt: to finicky app, so, we do this in terminal:
# install duti https://github.com/moretension/duti/
brew install duti
# then associate the protocol
duti -s net.kassett.finicky txmt
  1. restart the app

Upvotes: 0

ergosys
ergosys

Reputation: 49019

It doesn't appear to be difficult to register a system-wide URL handler for a protocol you design. In your handler you can send the file on to your IDE. The handler can be Cocoa based or applescript.

For a Cocoa solution, see this post. For a real world Cocoa example, you can look at bwana.

For an applescript solution, see this post or this post for a start.

Upvotes: 4

Blam
Blam

Reputation: 2965

Try using http://www.rubicode.com/Software/RCDefaultApp/

Upvotes: 1

Related Questions