From mboxrd@z Thu Jan 1 00:00:00 1970 From: Matt Lundin Subject: Re: capture with iceweasel/firefox -- nothing works Date: Fri, 03 Jun 2016 22:56:48 -0500 Message-ID: <8760tphain.fsf@fastmail.fm> References: Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43648) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b92hu-0001dx-Uo for emacs-orgmode@gnu.org; Fri, 03 Jun 2016 23:57:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b92hr-0000Oe-PJ for emacs-orgmode@gnu.org; Fri, 03 Jun 2016 23:57:06 -0400 Received: from out2-smtp.messagingengine.com ([66.111.4.26]:44859) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b92hp-0000GG-Cr for emacs-orgmode@gnu.org; Fri, 03 Jun 2016 23:57:03 -0400 In-Reply-To: (Samuel Wales's message of "Fri, 3 Jun 2016 18:23:09 -0700") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Samuel Wales Cc: emacs-orgmode@gnu.org Samuel Wales writes: > over many years, i have been trying to get org-protocol (or > anything similar) to work, and it is not working reliably. > > intermittently, it says there is a greedy protocol. the success rate > of capturing is around 50% maybe. when it is not working, it never > works. i have noticed no correlation with anything that could cause > this. > > sometimes it captures bogus text when i just want the link, but i > don't care about that. at least it copied the link. > > i've tried: > > 1) org-capture firefox extension > 2) a bookmark like this > - javascript:location.href%20=3D%20'org-protocol://capture-html://w/= '%20+%20encodeURIComponent(location.href)%20+%20'/'%20+%20encodeURIComponen= t(document.title)%20+%20'/'%20+%20encodeURIComponent(function%20()%20{var%2= 0html%20=3D%20"";%20if%20(typeof%20document.getSelection%20!=3D%20"undefine= d")%20{var%20sel%20=3D%20document.getSelection();%20if%20(sel.rangeCount)%2= 0{var%20container%20=3D%20document.createElement("div");%20for%20(var%20i%2= 0=3D%200,%20len%20=3D%20sel.rangeCount;%20i%20<%20len;%20++i)%20{container.= appendChild(sel.getRangeAt(i).cloneContents());}%20html%20=3D%20container.i= nnerHTML;}}%20else%20if%20(typeof%20document.selection%20!=3D%20"undefined"= )%20{if%20(document.selection.type%20=3D=3D%20"Text")%20{html%20=3D%20docum= ent.selection.createRange().htmlText;}}%20var%20relToAbs%20=3D%20function%2= 0(href)%20{var%20a%20=3D%20document.createElement("a");%20a.href%20=3D%20hr= ef;%20var%20abs%20=3D%20a.protocol%20+%20"//"%20+%20a.host%20+%20a.pathname= %20+%20a.search%20+%20a.hash;%20a.remove();%20return%20abs;};%20var%20eleme= ntTypes%20=3D%20[['a',%20'href'],%20['img',%20'src']];%20var%20div%20=3D%20= document.createElement('div');%20div.innerHTML%20=3D%20html;%20elementTypes= .map(function(elementType)%20{var%20elements%20=3D%20div.getElementsByTagNa= me(elementType[0]);%20for%20(var%20i%20=3D%200;%20i%20<%20elements.length;%= 20i++)%20{elements[i].setAttribute(elementType[1],%20relToAbs(elements[i].g= etAttribute(elementType[1])));}});%20return%20div.innerHTML;}()); > 3) a bookmark like this > - javascript:location.href=3D'org-protocol://capture://L/'+encodeURI= Component(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeU= RIComponent(window.getSelection()) > 4) i know there's a new one that is supposed to capture > format better (so you don't end up with a single > paragraph when there were several paragraphs). that > sounds wonderful! however, i am limited in computer > use (4 minutes at a time), so i don't know if it is > worth my trying or not. i have to use those 4 minutes responsibly. Here is the new style bookmark that works for me: javascript:location.href=3D'org-protocol://capture?url=3D'+encodeURICompone= nt(location.href)+'&title=3D'+encodeURIComponent(document.title)+'&body=3D'= +encodeURIComponent(window.getSelection()) I also placed the following in ~/.local/share/applications/emacsclient.desk= top: --8<---------------cut here---------------start------------->8--- [Desktop Entry] Name=3DEmacs Client Exec=3Demacsclient %u Icon=3Demacs-icon Type=3DApplication Terminal=3Dfalse MimeType=3Dx-scheme-handler/org-protocol; --8<---------------cut here---------------end--------------->8--- Since you are not using a desktop environment, you might also need to make sure that the appropriate xdg tools are installed. On arch linux the package is xdg-utils. I'd recommend copying and pasting the javascript line above into the location bar to confirm whether it works. If it does, you can then easily add it to your bookmarks. Note: There is a bug in the implementation of the new org-protocol url processing that can lead to multiple "greedy protocol" warnings. (I posted a bug report about this a week or so ago.) Hope this helps. Matt