Capture Links/Contents from Web Browsers or Other Applications
Firefox
Solution 1: From official org-capture site
The following is adapted from here.
-
Emacs setting with the following code.
12345(require 'server)(unless (server-running-p)(server-start));;for emacs clientrequire('org-protocol) -
Linux system setup (for KDE)
org-protocol.el – Intercept calls from emacsclient to trigger custom actions
12345678910111213141516Add a file =org.protocol= to =~/.kde/share/kde4/services/=:# -*- conf -*-[Protocol]protocol=org-protocolexec=/usr/bin/emacsclient '%u'input=noneoutput=nonehelper=truelisting=reading=falsewriting=falsemakedir=falsedeleting=falseIcon=emacsDescription=A protocol for org-mode -
Firefox setup
Please refer to http://kb.mozillazine.org/Register_protocol and use “org-protocol” as protocol for Firefox.
To actually use org-protocol add a bookmark to Firefox or Opera.
Here is the URL to use as “Location” for browser bookmarks. Just remove the line breaks and replace “sub-protocol” with the real sub-protocol to use:
1234567891011121314151617181920javascript:location.href='org-protocol://sub-protocol://x/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())#+END_SRC sh4. Add a org-capture template in Emacs#+BEGIN_SRC elisp(setq org-capture-templates(quote(("w""Default template"entry(file+headline "~/org/capture.org" "Notes")"* %^{Title}\n\n Source: %u, %c\n\n %i":empty-lines 1);; ... more templates here ...)))
Solution 2: Firefox plugins -the easiest way if you only want it to work with Firefox.
- Install the Firefox addon from here; source code link here.
-
Configure the addon.
-
Set up a capture template
123456789'(org-capture-templates(quote(("w" "Firefox Capture Template" entry(file+headline "ff-notes.org" "Firefox")"* BOOKMARKS %T\n%c\%a\n%i\n Tan's Note:%?" :prepend t :jump-to-captured t :empty-lines-after 1 :unnarrowed t)("t" "TODO" entry(file "refile.org")"* TODO %?\n%U\n%a" :clock-in t :clock-resume t))))) -
Highlight some text in Firefox and your fire shortcut key C-M-r, you should see a Emacs client popup with all the capture info.
Solution 3: Registering Org-Protocol with XDG-open
update: There is a plugin now for this method, see here for details. 05/07/2017-01:41:46 PM This method should work with other browsers (e.g. Chrome, and firefox etc) and applications (e.g. Acrobat), and it is a clean way of getting xdg-open (a tool for configuring default applications in Linux) to open org-protocol links and pass them to emacs. adopted and modified from those two links link1 , link2 and Registering Custom URI Handler
-
Add .desktop file, Create and save a file called org-protocol.desktop to ~/.local/share/applications containing:
12345678[Desktop Entry]Name=org-protocolExec=emacsclient %uType=ApplicationTerminal=falseCategories=System;MimeType=x-scheme-handler/org-protocol; -
Add org-protocol handler – for more about: Registering Custom URI Handler
1234nano ~/.local/share/applications/mimeapps.list[Added Associations]x-scheme-handler/org-protocol=org-protocol.desktop -
and run,
12$ 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.
-
Add config settings to dot-emacs file,
123(server-start)(require 'org-protocol)plus the capture template as in Solution 2/Step3.
-
Add Firefox bookmarklet with following javascript
12javascript:location.href='org-protocol://capture://w/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection())Note: 1. Bookmark Toolbar/New bookmark (with right click) to add bookmarklet 2.the w (in the javascript) is the shortcut key for the capture template.
- Select some text in a website and click on the Boolmarklet you just created. add the “/usr/bin/emacsclient” program if prompted.
- You should see the beautiful popup as in Solution 2 step 4.
Google Chrome or Chromium
Note: only tested Chrome here.
- Follow step 1-4 in Solution 3.
- Right click Bookmark Toolbar and Add a page to add a Bookmarklet (reference)
-
Follow step 6 and 7 in Solution 3, you should see popped up Emacs windows with captures.
For store-link to work in Firefox and Google Chrome
- Follow step 1-4 in Solution 3.
-
Add Bookmarklet for store-link with following javascript (updated May 2020).
123javascript:location.href='org-protocol://store-link?url='+ encodeURIComponent(location.href)+'&title='+ encodeURIComponent(document.title);// javascript:location.href='org-protocol://store-link://'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(window.getSelection()) -
use C-y to insert store-link in Emacs after invoke it in your Browsers.
http://www.mediaonfire.com/blog/2017_07_21_org_protocol_firefox.html
Adobe Acrobat Reader (update, finally working with help of RLM)
- Adapted from http://article.gmane.org/gmane.emacs.orgmode/6810
-
Place a javascript file for each menu entry in ~/.adobe/Acrobat/9.0/JavaScripts on unix-like systems. org-store-link.js from http://article.gmane.org/gmane.emacs.orgmode/6810
123app.addMenuItem({cName:"org-capture", cParent:"Tools",cExec:"app.launchURL('org-protocol://store-link://f/' + encodeURIComponent(this.URL) + '::' + encodeURIComponent((this.pageNum+1)) + '/' + encodeURIComponent(this.info.Title)+'/',true);"});org-capture.js from http://article.gmane.org/gmane.emacs.orgmode/6810
123app.addMenuItem({cName:"org-capture", cParent:"Tools",cExec:"app.launchURL('org-protocol://capture://f/' + encodeURIComponent(this.URL) + '::' + encodeURIComponent((this.pageNum+1)) + '/' + encodeURIComponent(this.info.Title)+'/',true);"});Note: this.page.Num+1 is used get the page number index.
-
The examples given here will place new menu entries in the “Tools” menu, after restarting Adobe Reader.
- check Enable Menu Items JavaScript Execution Privileges under Edit > Preferences > Javascript Otherwise, internal error messages.
-
Create a capture templates in dot-emacs file
1234("f" "PDF Capture Template" entry(file+headline "PDF-notes.org" "Firefox")"* BOOKMARKS %T\n%c\%a\n%i\n\n Tan's Note:%?" :prepend t :jump-to-captured t :empty-lines-after 1 :unnarrowed t) -
Assign Evince for opening PDF file at captured page
123456789;;RLM for evince(setq org-file-apps'((auto-mode . emacs)("\\.mm\\'" . default)("\\.x?html?\\'" . default)("\.pdf::\\(.*\\)" . "evince -i %1 %s")("\.pdf" . "evince %s")))Note: Acroread is incapable of deciphering its own page indexing system. Evince -i (NOT p) is employed to navigate to the target page correctly.
-
Capture PDF file link with page index.
Issues: Each triggers two FireFox windows popups (if FF is open) with a error message. Sometimes triggers double capture too. Acrobat sorely lacks of Selection Object, so the selection capture as in Browsers seems not possible, which is minor since a simple copy-and-paste takes care of it.
MAR
About the Author:
Beyond 8 hours - Computer, Sports, Family...