Samuel Wales <samolog...@gmail.com> 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=%20'org-protocol://capture-html://w/'%20+%20encodeURIComponent(location.href)%20+%20'/'%20+%20encodeURIComponent(document.title)%20+%20'/'%20+%20encodeURIComponent(function%20()%20{var%20html%20=%20"";%20if%20(typeof%20document.getSelection%20!=%20"undefined")%20{var%20sel%20=%20document.getSelection();%20if%20(sel.rangeCount)%20{var%20container%20=%20document.createElement("div");%20for%20(var%20i%20=%200,%20len%20=%20sel.rangeCount;%20i%20<%20len;%20++i)%20{container.appendChild(sel.getRangeAt(i).cloneContents());}%20html%20=%20container.innerHTML;}}%20else%20if%20(typeof%20document.selection%20!=%20"undefined")%20{if%20(document.selection.type%20==%20"Text")%20{html%20=%20document.selection.createRange().htmlText;}}%20var%20relToAbs%20=%20function%20(href)%20{var%20a%20=%20document.createElement("a");%20a.href%20=%20href;%20var%20abs%20=%20a.protocol%20+%20"//"%20+%20a.host%20+%20a.pathname%20+%20a.search%20+%20a.hash;%20a.remove();%20return%20abs;};%20var%20elementTypes%20=%20[['a',%20'href'],%20['img',%20'src']];%20var%20div%20=%20document.createElement('div');%20div.innerHTML%20=%20html;%20elementTypes.map(function(elementType)%20{var%20elements%20=%20div.getElementsByTagName(elementType[0]);%20for%20(var%20i%20=%200;%20i%20<%20elements.length;%20i++)%20{elements[i].setAttribute(elementType[1],%20relToAbs(elements[i].getAttribute(elementType[1])));}});%20return%20div.innerHTML;}()); > 3) a bookmark like this > - > javascript:location.href='org-protocol://capture://L/'+encodeURIComponent(location.href)+'/'+encodeURIComponent(document.title)+'/'+encodeURIComponent(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='org-protocol://capture?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title)+'&body='+encodeURIComponent(window.getSelection()) I also placed the following in ~/.local/share/applications/emacsclient.desktop: --8<---------------cut here---------------start------------->8--- [Desktop Entry] Name=Emacs Client Exec=emacsclient %u Icon=emacs-icon Type=Application Terminal=false MimeType=x-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