How can I make org-protocol work on Openbox?

前端 未结 2 1194
甜味超标
甜味超标 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条回答
  • 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.

    0 讨论(0)
  • 2021-01-31 05:48

    The following steps for setting up org-protocol work with Ubuntu 16.04 (Xenial Xerus) and presumably later versions. Org-mode is assumed to have already been set-up (and installed using apt-get install org-mode or via the ELPA repository).

    Set-up

    1. Add .desktop file

    Create and save a file called org-protocol.desktop to ~/.local/share/applications containing:

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

    Then run:

    $ update-desktop-database ~/.local/share/applications/
    

    This step makes Firefox aware that "org-protocol" is a valid scheme-handler or protocol (by updating ~/.local/share/applications/mimeinfo.cache), and causes Firefox to prompt for a program to use when opening these kinds of links.

    1. Add config settings to ~/.emacs.d/init.el (or ~/.emacs) file

    Have the following settings in your Emacs configuration file:

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

    Also add some template definitions to the configuration file, for example:

    (setq org-protocol-default-template-key "l")
    (setq org-capture-templates
     '(("t" "Todo" entry (file+headline "/path/to/notes.org" "Tasks")
            "* TODO %?\n  %i\n  %a")
       ("l" "Link" entry (file+olp "/path/to/notes.org" "Web Links")
            "* %a\n %?\n %i")
       ("j" "Journal" entry (file+datetree "/path/to/journal.org")
            "* %?\nEntered on %U\n  %i\n  %a")))
    

    Now run Emacs.

    1. Create your notes.org file

    Assuming you use the capture templates defined in step 2, you will need to prepare a notes.org file at the location you specified in step 2. You must create this file -- if it is not created along with the headlines specified in step 2, org-mode will just give a warning when you try to capture web-pages. So, given the capture templates from step 2, notes.org should contain the following:

    * Tasks
    * Web Links
    
    1. Add bookmarklet(s) to Firefox

    Save bookmark to toolbar containing something like the following as the location:

    javascript:location.href='org-protocol://capture?template=l&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection())
    

    If you are using an older version of org-mode, you may need to use the following instead:

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

    Notice the 'l' (lowercase L) in the above URL -- this is what chooses the capture template (automatically) -- it is the key one would normally have to press when capturing with org-mode via C-c c.

    When you click on this bookmarklet, Firefox will ask what program to use to handle the "org-protocol" protocol. You can simply choose the default program that appears ("org-protocol").

    Using it

    (Optionally) select some text on a webpage you're viewing in Firefox. When you click on the bookmarklet, the link and selected text will be placed in the Emacs capture buffer. Go to Emacs, modify the capture buffer as desired, and press C-c C-c to save it.

    0 讨论(0)
提交回复
热议问题