Coder Social home page Coder Social logo

org-protocol-handler's Introduction

Org Protocol Handler

The Org Protocol Handler is a small AppleScript/Python application that registers itself as the handler for all org-protocol:// links.

If your system wants to visit an org-protocol:// link, it will pass the value to this application, which will urldecode it and pass it to emacsclient. The net effect is that you can use a bookmarklet to build an org-protocol:// link in your browser for things like saving the current page as a link in Org and that bookmarket will launch and focus Emacs.

Configuration

In order for this application to work for you, you will need to be sure that it is pointed to the correct copy of emacsclient on your system.

Out of the box, it will run /usr/local/bin/emacsclient, which should be the correct copy if you are using Emacs from Homebrew. If you are not, or if that path differs in some way, you will need to create a configuration file.

Create a file called ~/.orgprotocol.ini. Note the leading period in the filename. This file should simply contain these two lines:

[emacsclient]
path=/path/to/your/emacsclient

How does it work?

In OS X, any application that exists in your root /Applications directory and that contains a CFBundleURLTypes stanza in its Info.plist will be registered as a handler for the URL schemes described there.

In the case of this application, the stanza looks like this:

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleURLName</key>
        <string>EmacsClientCapture</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <string>org-protocol</string>
        </array>
    </dict>
</array>

In my understanding, the CFBundleURLName makes no difference at all, it just needs to be set to something. When any program on your system attempts to visit a URL beginning with org-protocol://, OS X will launch this application and hand it the URL through some known OS X API mechanism.

In AppleScript, accessing that data is quite simple, you need only define an on open location subroutine that accepts the whole URL as a string and then you can do what you like with it.

This application is designed to accept an org-protocol:// URL and it simply launches emacsclient and hands that URL to it. This enables your already-running Emacs server to be triggered by org-protocol:// links from anywhere on your system.

Neither the emacsclient program nor Emacs itself will decode the URL; it expects to receive a raw URL with spaces and all, but the URL will need to be encoded to preserve spaces (especially) when the handler is called by your browser, so this handler uses a small Python script to decode the URL and also extract the page title from it so we can display a notification.

Why?

In short, so that you can save things from your web browser directly into Org capture templates or simply save the links to pages for later insertion into Org documents.

org-protocol-handler's People

Contributors

aaronbieber avatar andrewsanchez avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.