How can I make org-protocol work on Openbox?

前端 未结 2 1193
甜味超标
甜味超标 2021-01-31 05:25

I tried the instructions - I am using Firefox on Lubuntu (Openbox). But I get the error

"Firefox doesn\'t know how to open this address, because the pr

2条回答
  •  旧时难觅i
    2021-01-31 05:44

    Add protocol handler

    Create file ~/.local/share/applications/org-protocol.desktop containing:

    [Desktop Entry]
    Name=org-protocol
    Exec=emacsclient %u
    Type=Application
    Terminal=false
    Categories=System;
    MimeType=x-scheme-handler/org-protocol;
    

    Note: Each line's key must be capitalized exactly as displayed, or it will be an invalid .desktop file.

    Then update ~/.local/share/applications/mimeinfo.cache by running:

    • On GNOME:

      update-desktop-database ~/.local/share/applications/
      
    • On KDE:

      kbuildsycoca4
      

    Configure Emacs

    Init file

    Add to your Emacs init file:

    (server-start)
    (require 'org-protocol)
    

    Capture template

    You'll probably want to add a capture template something like this:

    ("w" "Web site"
     entry
     (file+olp "/path/to/inbox.org" "Web")
     "* %c :website:\n%U %?%:initial")
    

    Note: Using %:initial instead of %i seems to handle multi-line content better.

    This will result in a capture like this:

    \* [[http://orgmode.org/worg/org-contrib/org-protocol.html][org-protocol.el – Intercept calls from emacsclient to trigger custom actions]] :website:
    [2015-09-29 Tue 11:09] About org-protocol.el
    
    org-protocol.el is based on code and ideas from org-annotation-helper.el and org-browser-url.el.
    

    Configure Firefox

    Expose protocol-handler

    On some versions of Firefox, it may be necessary to add this setting. You may skip this step and come back to it if you get an error saying that Firefox doesn't know how to handle org-protocol links.

    Open about:config and create a new boolean value named network.protocol-handler.expose.org-protocol and set it to true.

    Note: If you do skip this step, and you do encounter the error, Firefox may replace all open tabs in the window with the error message, making it difficult or impossible to recover those tabs. It's best to use a new window with a throwaway tab to test this setup until you know it's working.

    Make bookmarklet

    Make a bookmarklet with the location:

    javascript:location.href='org-protocol://capture://w/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())
    

    Note: The w in the URL chooses the corresponding capture template. You can leave it out if you want to be prompted for the template.

    When you click on this bookmarklet for the first time, Firefox will ask what program to use to handle the org-protocol protocol. If you are using Ubuntu 12.04 (Precise Pangolin), you must add the /usr/bin/emacsclient program, and choose it. With Ubuntu 12.10 (Quantal Quetzal) or later, you can simply choose the default program that appears (org-protocol).

    You can select text in the page when you capture and it will be copied into the template, or you can just capture the page title and URL.

    Pentadactyl

    If you're using Pentadactyl, you can map key sequences something like this:

    map cc -javascript location.href='org-protocol://capture://w/'+encodeURIComponent(content.location.href)+'/'+encodeURIComponent(content.document.title)+'/'+encodeURIComponent(content.document.getSelection())
    

    Note: The JavaScript objects are slightly different for running from Pentadactyl.

    You might also want to add one for the `store-link` sub-protocol, like:

    map cl -javascript location.href='org-protocol://store-link://'+encodeURIComponent(content.location.href)+'/'+encodeURIComponent(content.document.title)
    

    Capture script

    You may want to use this script to capture input from a terminal, either as an argument or piped in:

    #!/bin/bash
    
    if [[ $@ ]]
    then
        data="$@"
    else
        data=$(cat)
    fi
    
    if [[ -z $data ]]
    then
        exit 1
    fi
    
    encoded=$(python -c "import sys, urllib; print urllib.quote(' '.join(sys.argv[1:]), safe='')" "${data[@]}")
    
    # "link" and "title" are not used, but seem to be necessary to get
    # $encoded to be captured
    emacsclient "org-protocol://capture://link/title/$encoded"
    

    Then you can capture input from the shell like this:

    tail /var/log/syslog | org-capture
    
    org-capture "I can capture from a terminal!"
    

    These instructions are more up-to-date than the ones in Mark's answer.

提交回复
热议问题