Code Monkey home page Code Monkey logo

org-capture-extension's Introduction

Org Capture Extension

This is an extension for Google Chrome (tm) and Firefox (tm) which adds a "Capture" button, sending the site address, title, and selected text (if any) to emacs via org-protocol, see the Org-Mode site for instructions for setting that up org-protocol. The extentsion itself is available at the Chrome App Store.

Improvements

  • Adding options for selecting the exact structure of the links that are constructed (e.g. for the benefit of people with '///' problems).
  • There is always room to improve. Open a ticket with your ideas.

Example Usage

Example Usage Video Example Usage Screenshot

Problems? Please click here or scroll to the bottom.

Detailed setup instructions

Install the extension

Either via the Chrome App Store or by dragging the extension folder to the "Extensions" tab in Chrome. If the latter is the chosen procedure then one needs to enable developer mode first, if I'm not mistaken. Note that if you choose to have a local-install, then you need to choose some icon and name it org-mode-unicorn.png, placing it in the extension's folder. Or, you can name it anything you want, but then you need to update manifest.json.

Note: The first time you use the extension, Chrome will ask you allow it to run open .... (on OSX) or xdg-open ... (on Linux), or ??? (On Windows). Those are the standard system mechanisms for dispatching a file/URL to the appropriate handler, so you should accept the request.

Set up org-protocol

Detailed instructions available at Org-Mode site.

The gist of it is to make your system recognize emacsclient as the handler of org-protocol:// links. In addition, one needs to set up emacs to load org-protocol and to set up capture templates.

Register emacsclient as the org-protocol handler

Under Linux

cat > "${HOME}/.local/share/applications/org-protocol.desktop" << EOF
[Desktop Entry]
Name=org-protocol
Exec=emacsclient %u
Type=Application
Terminal=false
Categories=System;
MimeType=x-scheme-handler/org-protocol;
EOF

And then, for GTK-based DE:

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

For KDE5:

kbuildsycoca5
xdg-mime default org-protocol.desktop x-scheme-handler/org-protocol
For KDE4
Note: This is a workaround to issue #16 - See comment here

Create the file /usr/local/bin/emacs-capture

#!/bin/bash

# HACK: workaround for a kde-open bug (feature?) that might have
#       eaten a colon from our argument, om nom nom
argv=()
for arg in "$@"; do
    re='s_^org-protocol:/+capture:?/+_org-protocol://capture://_'
    argv+=("$(echo -n "$arg" | sed -Ez "$re")")
done

# Note: feel free to add any other arguments you want,
#  e.g. emacsclient --alternate-editor= -c "${argv[@]}"
emacsclient "${argv[@]}"

And the file

$HOME/.local/share/applications/emacs-capture.desktop

#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Emacs Client
Exec=emacs-capture "%u"
Icon=emacs-icon
Type=Application
Terminal=false
MimeType=x-scheme-handler/org-protocol;

Finally, run

kbuildsycoca4
sudo update-desktop-database

Under OSX

Start Applescript Editor. Paste the following snippet:

on emacsclient(input)
	do shell script "/Applications/Emacs.app/Contents/MacOS/bin-x86_64-10_9/emacsclient -n -c -a \"/Applications/Emacs.app/Contents/MacOS/Emacs\" '" & input & "'"
end emacsclient

on open location input
	emacsclient(input)
end open location

on open inputs
	repeat with raw_input in inputs
		set input to POSIX path of raw_input
		emacsclient(input)
	end repeat
end open

on run
	do shell script emacsclient("")
end run

Adjust the paths and save it (with 'type' as Application) under /Applications/EmacsClient.app (or whatever else you choose). Edit (with Xcode) the file /Applications/Emacsclient.app/Contents/Info.plist

And add there the following:

<key>CFBundleURLTypes</key>
<array>
	<dict>
		<key>CFBundleURLName</key>
		<string>org-protocol</string>
		<key>CFBundleURLSchemes</key>
		<array>
			<string>org-protocol</string>
		</array>
	</dict>
</array>

and

<key>CFBundleDocumentTypes</key>
<array>
	<dict>
		<key>CFBundleTypeExtensions</key>
		<array>
			<string>*</string>
		</array>
		<key>CFBundleTypeName</key>
		<string>All</string>
		<key>CFBundleTypeOSTypes</key>
		<array>
			<string>****</string>
		</array>
		<key>CFBundleTypeRole</key>
		<string>Viewer</string>
	</dict>
</array>

and restart the desktop. You can also download EmacsClient.app.zip, which I prepared in advance, if you are lazy.

Install EmacsClient.app with homebrew cask

If you have Homebrew and Homebrew-Cask installed, you can also install EmacsClient.app.zip with brew cask install emacsclient

Frame Visibility

Under some setups the emacs frame does not appear on top. @dangom proposes a workaround using hammerspoon:

Add the following to your init.lua:

function emacsclientWatcher(appName, eventType, appObject)
  if (eventType == hs.application.watcher.activated) then
    if (appName == "Emacsclient") then
      -- Bring Emacs to Front
      hs.osascript.applescript('tell application "Emacs" to activate')
    end
  end
end
appWatcher = hs.application.watcher.new(emacsclientWatcher)
appWatcher:start()

Under Windows

Open the Registry Editor (Win-R, then type regedit). Within HKEY_CLASSES_ROOT, add a key called org-protocol. Within org-protocol, set the data for the string value with the name (Default) to be URL:org-protocol, add another string value with name URL Protocol and no data, and add a key called shell.

Within shell, create a key called open.

Within open, create a key called command.

Within command, set the data for the string value with the name (Default) to "C:\the\path\to\your\emacsclientw.exe" "%1", updating the path to point to your Emacs installation.

If you get stuck, see this guide to registering a protocol handler and look at how registries are set up for other protocol handlers (skype, ftp, etc.). Most of your pre-existing protocol handlers have more config than you need.

Set up handlers in emacs

If some text is selected before the button is clicked, then the following is sent to emacs:

org-protocol://capture:/p/<url>/<title>/selection>

If nothing is selected, then instead the following is sent:

org-protocol://capture:/L/<url>/<title>

This means that you need to have appropriate capture templates for "L" and for "p". Example templates below:

(setq org-capture-templates `(
	("p" "Protocol" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
        "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?")
	("L" "Protocol Link" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
        "* %? [[%:link][%:description]] \nCaptured On: %U")
))

Hint: You can put code in capture handlers via %() blocks. I use this mechanism to automatically close the newly crated frame in the L template. If anyone cares to know, I'll add the details. Another example use is below.

Note: The L template above would break for links to pages having [ and ] characters in their page titles - notably ArXiv. To mitigae this, you can use the improved template, contributed by Vincent Picaud:

(defun transform-square-brackets-to-round-ones(string-to-transform)
  "Transforms [ into ( and ] into ), other chars left unchanged."
  (concat 
  (mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform))
  )

(setq org-capture-templates `(
	("p" "Protocol" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
        "* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?")	
	("L" "Protocol Link" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
        "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
))

Example: closins the frame after a capture

If you wish to automatically close the emacs frame after a capture, add the following template:

("L" "Protocol Link" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
 "* %? [[%:link][%:description]] %(progn (setq kk/delete-frame-after-capture 2) \"\")\nCaptured On: %U"
 :empty-lines 1)

and in the initialization of org-mode put:

  ;; Kill the frame if one was created for the capture
  (defvar kk/delete-frame-after-capture 0 "Whether to delete the last frame after the current capture")

  (defun kk/delete-frame-if-neccessary (&rest r)
    (cond
     ((= kk/delete-frame-after-capture 0) nil)
     ((> kk/delete-frame-after-capture 1)
      (setq kk/delete-frame-after-capture (- kk/delete-frame-after-capture 1)))
     (t
      (setq kk/delete-frame-after-capture 0)
      (delete-frame))))

  (advice-add 'org-capture-finalize :after 'kk/delete-frame-if-neccessary)
  (advice-add 'org-capture-kill :after 'kk/delete-frame-if-neccessary)
  (advice-add 'org-capture-refile :after 'kk/delete-frame-if-neccessary)

Troubleshooting

Is the extension not working as you expect? i.e., is it "broken"? You need to do some investigative legwork. And if you open a ticket, provide enough information to help solve the problem!

Please describe your setup. Linux? Version. OSX? Version. Emacs? Version. org-mode? Version. Chrome? Version. How did you get your system to send org-protocol links to emacs? Please provide the relevant capture templates.

Please find the simplest URL for which it fails (does it work on a simple address that contain only alphanumeric characters and periods? and backslashes? and query parameters? and escaped characters? etc.). Then open the developer console and look for the debug message that the extension gives and add it to the ticket.

Open a terminal and run $open "COPIED-URL" (do not skip the quotes, unless what you are pasting already has quotes around it). $open is simply open if you are on OSX and xdg-open if on linux. COPIED-URL is obviously the url you pasted here in step 1. Does it work? Congrats, you found where the problem is not (i.e. inside chrome). No? Does $open org-"protocol://capture:/p/a/b" work? No? Again you found where the problem lies not. Otherwise proceed to step 3.

Call up the line you ran in the terminal with the non-working url. it will be of the form open "org-protocol://capture://PIECE1/PIECE2/ with PIECE2 usually being longer and more complex if you selected any text, and PIECE1 otherwise. Please edit the url until it is as short as possible while still breaking (Note, % should always be proceeded by two digits/letters in the ranges 0-9 and A-F so do not leave a percent sign with a single symbol following). You can probably trim one of the pieces to be just one character. Add to the ticket the smallest breaking URL.

Try sending said URL directly to emacsclient, for good measure. Does it work? Again, congrats. If you are using OSX, make sure that the emacsclient which you call is the correct one!

P.S.

It is of course fine to ask for help with problems in your config as well.

License

This repository is licensed as MIT license, see the LICENSE file for details.

org-capture-extension's People

Contributors

anton-latukha avatar bbigras avatar benalbrecht avatar jabranham avatar jdpopkin avatar sprig avatar swflint avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

org-capture-extension's Issues

Fails to work in brave browser

In this version of the brave browser,

Brave 0.60.48 Chromium: 72.0.3626.121 (Official Build) (64-bit)
Revision da3787ba355f18db7db52abf75c42afb408d656f-refs/branch-heads/3626@{#883}
OS Linux

Clicking the capture button flashes the "captured" message, then immediately opens
a new tab and never communicates with emacs. (It's currently working in Firefox.)

Not sure if this is a problem with brave or with the extension, but I thought I'd report it here anyway.

Cheers, and thanks!
--Alain

Problem with Emacs as alias instead of Emacs.app

Hi there,
I'm on Mac Mojave and use railwaycat emacs with a symlink ln to /Applications. The problem is that the emacsclient in /Applications is looking to pass off the instructions to things contained in Emacs.app but the symlink doesn't have anything inside of it of course, and it doesn't seem to pass those instructions off to the Emacs.app over at /usr/local/Cellar/emacs-mac/emacs-26.3-z-mac-7.7/
I was thinking that I could just redo the script by hand, but I've never futzed around with that and I'd probably break it badly, and I'd have to redo it every time it upgrades to a new version as well (as it'd be pointing in a different place). I'm just wondering if there's a workaround for that somehow?

Thanks for any help!

Org-protocol links no longer call out

On Chromium Version 58.0.3029.110 (64-bit) running on NixOS, neither of the following links call out to emacs (and xdg is correctly set up, a hand-crafted link will have no problems).

  • javascript:location.href='org-protocol://capture?template=b&title='+encodeURIComponent(document.title)+'&url='encodeURIComponent(location.href)
  • javascript:location.href='org-protocol://store-link?title='+encodeURIComponent(document.title)+'&url='encodeURIComponent(location.href)

However, if org-protocol://capture?template=b&title=foo&url=flintfam.org is entered directly in the address bar, there is no problem.

Capture impossible via org-protocol probably due to a user error

👋 Hello,

I have been trying to make the org-capture-extension work on my setup but I am still failing to get the whole process work fine. I tried all troubleshooting options and identified that my problem probably comes from my emacs configuration (I.e. after the execution emacsclient org-protocol://capture:/p/a/b).

  1. The org-capture-extension seems to work as expected as it opens my emacs window (via emacsclient)
  2. My org-capture-templates configuration seems to be correct, as I can successfully capture something “by hand” inside emacs (M-x org-capture followed by p opens a correct Capture buffer)
  3. The manual execution of emacsclient org-protocol://capture:/p/a/b in my terminal doesn't work 😞

Please find below a screenshot of the error:

  1. The left buffer *help* describes the content of by org-capture-extension variable
  2. The top right buffer CAPTURE-notes.org is the buffer that opens when I manually execute the capture via M-x org-capture followed by p
  3. The bottom right buffer b is the newly opened buffer after executing emacsclient "org-protocol://capture:/p/a/b" manually in my terminal
    Screenshot from 2020-04-23 11-35-41

Versions used on my computer:

  • GNU Emacs 26.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.5) of 2019-08-20
  • Firefox 75.0

Any help would be very much appreciated 🙇‍♂️ and thanks for this extension which seems very promising!

Would like to close emacs window automatically

Hi,
you mention in the docs that you can use %() blocks with L to automatically close the opened capture window. I'm not sure if this is what I want, but basically I want to add my L template to my links.org file automatically. So I use :immediate-finish in the capture template and that works well. But I've not found a way to kill the opened extra emacs window that opened.

Any suggestions how to do that please?

Greedy handler issue when no problem with org-capture template -- on Firefox Quantum and Chrome

Hello @sprig, how are you doing?

This issue is actually closed now, but I wanted to make sure I communicated an issue that affects the extension. Looks like there were some recent changes to the Emacs use-package package, which was interfering with the org-capture templates. Here is the link to the issue

jwiegley/use-package#557

Let me tell you how I found the issue in case you get other people registering similar issues.

I set up the org-capture-extension as you recommended in the README, however I keep getting the following error (posted below) in emacs Messages buffer. I am using Emacs 25.3 on Ubuntu 16.04x64 with the new Firefox Quantum browser as well as Chrome.

Greedy org-protocol handler.  Killing client. 
No server buffers remain to edit.

So I tried to manually pass a link through the emacsclient with the following command

emacsclient -n "org-protocol:///capture?url=http%3a%2f%2fduckduckgo%2ecom&title=DuckDuckGo"

But I kept getting this strange response in the Messages buffer where there was a cycling behavior between warning349 and warning 931.

condition-case: Symbol’s value as variable is void: use-package--warning349
condition-case: Symbol’s value as variable is void: use-package--warning931
condition-case: Symbol’s value as variable is void: use-package--warning349
condition-case: Symbol’s value as variable is void: use-package--warning931
condition-case: Symbol’s value as variable is void: use-package--warning349

Let me know if you have any questions.

No longer works. Opens new window.

After working flawlessly for months, this no longer works on a recent Chromium version.

I have Chromium 46.0.2490.80 on Linux.

Now the extension opens a new Chromium window instead of sending the capture to emacs.

Needs a keybinding

This has worked great for me so far; thanks for making it available.

The one thing I miss versus the old extension is a keybinding---being an aged Emacser, my relationship with the mouse is spotty at best.

Org captue results in Emacs opening ~/org-capture/... file instead of triggering org-capture

I'm using the default configuration on the emacs side ((require org-protocol)).

I got the bookmarklet working correctly from chrome:

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

However the extension doesn't work on both FF and Chrome - it sends me to an empty buffer that is being opened as ~/org-protocol:/capture/?template=l&url=XXX

I think the URL formatted by the bookmarklet is the more "correct" one as it works correctly both through xdg-open and through the bookmarklet in Chrome...

Broken with last org-mode version

Hello, the extension is broken (tested with Firefox and Chrome), probably related to an org-mode update. Links are inserted like that in org file, with strange escape characters:

[[https%253A%252F%252Fgithub.com%252Fsprig%252Forg-capture-extension][sprig%2Forg-capture-extension%3A%20A%20Chrome%20and%20firefox%20extension%20facilitating%20org-capture%20in%20emacs]]

Frame visibility on top

The Emacs capture frame opens but is hidden by the browser (Firefox) window. I am using macOS so went with the Applescript handler. Is there a way to display the capture frame on top of the other windows? Or switch to the frame directly?

Firefox 58 (nightly) does not register org-protocol URL handler scheme

I'm using Firefox Nightly (Firefox 58 version currently).
When I click the "Org Capture" icon, firefox opens:

org-protocol://capture?template=L&url=http%3A%2F%2Fwww.a-hospital.com%2Fw%2F%25E4%25BA%2592%25E5%258A%25A8%25E7%2589%2588%25E4%25BA%25BA%25E4%25BD%2593%25E7%25A9%25B4%25E4%25BD%258D%25E5%259B%25BE&title=%E4%BA%92%E5%8A%A8%E7%89%88%E4%BA%BA%E4%BD%93%E7%A9%B4%E4%BD%8D%E5%9B%BE%20-%20A%2B%E5%8C%BB%E5%AD%A6%E7%99%BE%E7%A7%91&body=

It does not open Linux script emacs-capture.

Greedy org-protocol handler. Killing client.

I get this in emacs when I click the button :

Greedy org-protocol handler.  Killing client.
No server buffers remain to edit

GNU Emacs 24.4.1 (x86_64-w64-mingw32) of 2014-10-20 on KAEL

Capture tab screenshot

It would be useful if a small screenshot of the captured tab could be provided to org-mode. I’ve noticed that Firefox appears to store a screenshot when adding a bookmark as of late (though screenshots are currently only shown in the »new bookmark« popup). I’m not quite sure where they are stored (they don’t seem to be referenced in the places.sqlite database). Perhaps the screenshots could be repurposed if they are accessible somewhere.

Since screenshots will be too large to transmit as a URL parameter, perhaps they could be stored to a temporary location (if the web extensions API permits that) and that location could be encoded inside the capture URL.

use expand-file-name rather than concat with org-directory

I would like to suggest that the setup instruction be modified. Rather than

(concat org-directory "notes.org")

I think following should be used

(expand-file-name "notes.org" org-directory)

The latter works whether or not the value of org-directory has trailing slash.
On my emacs 27, the default value of this is "~/org" without a trailing slash.

How to make it to working?

Hi,

I cannot get the extension to work. It seems so that something is happening behind the scenes but I cannot get the text with the capture template. This is what I did:

  • Installed the chrome extension from the store
  • I registered emacsclient as the org-protocol handler (non-KDE, in fact I use AwesomeWM, a tiling WM without DE, similar to i3)
  • I updated my .spacemacs config to include the capturing templates
  • Started emacs as a server
  • Tested it. It didn't work, so to troubleshoot I pasted the org-protocol url bellow into firefox. I get promped with which app I should open org-protocol. I click open and then emacs is fired up, and on the bottom I get to see the URL, but the buffer remains blank.

org-protocol://capture?template=L&url=https%3A%2F%2Fgithub.com%2Fsprig%2Forg-capture-extension&title=sprig%2Forg-capture-extension%3A%20A%20Chrome%20and%20firefox%20extension%20facilitating%20org-capture%20in%20emacs&body=?

Additional information, I also use edit with emacs[1] which uses an edit server. I don't think it is interfering but just in case it is worth mentioning.
[1]: https://chrome.google.com/webstore/detail/edit-with-emacs/ljobjlafonikaiipfkggjbhkghgicgoh?hl=en

I am not very experienced with emacs. Any idea please?

Thank you

Where is the capture entry?!

  • Platform/envir:

    • Linux laptop 4.15.0-20-generic #21-Ubuntu SMP Tue Apr 24 06:16:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
    • DISTRIB_DESCRIPTION="Linux Mint 19 Tara"
    • XDG_CURRENT_DESKTOP=X-Cinnamon
    • Mozilla Firefox 70.0
    • GNU Emacs 26.3
  • Install

    • I added org-capture from Firefox:
    $ grep -oP '(?<=\},\"name\":\")([^"]*)' ~/.mozilla/firefox/*.default/addons.json | grep Org
    Org Capture
    
    $ cat "${HOME}/.local/share/applications/org-protocol.desktop"
    [Desktop Entry]
    Name=org-protocol
    Exec=emacsclient %u
    Type=Application
    Terminal=false
    Categories=System;
    MimeType=x-scheme-handler/org-protocol;
    
    $ update-desktop-database -v ~/.local/share/applications/
    Search path is now: [/home/er/.local/share/applications/]
    File "/home/er/.local/share/applications/userapp-evince-RA09XZ.desktop" lacks MimeType key
    
  • Runtime:

    • Actions:

      • Emacs session open.
      • I click on the Org-capture button from a tab in Firefox.
    • Behavior:

      • Expected: creation of Capture entry to show in the active buffer *scratch*.
      • Actual: "Captured" flashes and nothing else.

Can org-capture-extension be made to work on a chromebook ?

I got org capture to work on MacOS, since there is a OS built-in URL dispatch mechanism.

Is there a way to make org capture to work on chromeOS - maybe for emacs running in crostini, or maybe for a native emacs app (there are a few) ?

Extension doesn't work (MacOS El Capitan)

Nothing happens when I click the extension button (I don't get a confirmation dialog the first time I click it after installing/reinstalling the extension if that means anything).

I am able to successfully use the links in the org-protocol documentation to verify my emacsclient and protocol handler setup, so I think the problem is in the extension but I'm not sure how to figure it out.

License issues

The sentence in the MIT License saying

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

indicates that the license should be applied to all source files.

Copyright (c) <year> <copyright holders>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Firefox support

Hi -

Just an FYI - your extension also works on Firefox. I've tested it on Firefox 51 (current stable release) and Firefox 53 (developer edition). Firefox users can use Chrome Store Foxified to install it directly without any issues (though it requires a Firefox account).

If you want to, you can upload it to Firefox's Add-ons page fairly easily. There's info on that process here: https://developer.mozilla.org/en-US/Add-ons/Distribution

Thanks for your work on this extension!

capture fails in one template, ok in another?

The capture works in this template:
("p" "Phone call" entry (file "refile.org") "* TODO CALL %? :PHONE:\n%U" :clock-in t :clock-resume t)
But NOT in the following one (with error -No server buffers remain to edit):
("p" "Protocol" entry (file+headline ,(concat org-directory "ff-notes.org") "Inbox") "* %^{Title}\nSource: %u, %c\n#+BEGIN_QUOTE\n%i\n#+END_QUOTE\n%?")
I am using Emacs 25.5, org-mode 9.0.5 Firefox 53.0 (64bit).

Activate via context menu

It would be convenient to have Org Capture context menu so that user would:

  • select text to capture
  • press right mouse button
  • and the action is right here, under the cursor.

getting the extension to talk to emacs

I am running chrome-8.0 and emacs25 on Linux Mint.

I have installed the extension from the chrome store,
I have an emacs server running that emacsclient can connect to
and I executed:

gconftool-2 -s /desktop/gnome/url-handlers/org-protocol/command '/usr/local/bin/emacsclient %s' --type String
gconftool-2 -s /desktop/gnome/url-handlers/org-protocol/enabled --type Boolean true

on my machine as stated in the org-protocol docs.

When I click the extesion's button I get a pop-up saying it wants to open the link with xdg-open.
What do I need to do to get it to talk to the emacs server instead?

`org-protocol://capture` is cut off from URL

Hi @sprig,

Happy new year! Apologies for bothering you on this holiday, but I am sort of stuck making this work.

When I capture a web page in Firefox (both with and without selected text), Emacs opens a file starting with ?template=, followed by the template identifier and the site information. I checked the developer console and it provides the following information:

Capturing the following URI with new org-protocol: org-protocol://capture?template=L&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FOrg-mode&title=Org-mode%20-%20Wikipedia&body=,

which looks quite fine to me. Moreover, things work perfectly in case I send the URI directly to emacsclient from the shell, that is:

emacsclientw.exe "org-protocol://capture?template=L&url=https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FOrg-mode&title=Org-mode%20-%20Wikipedia&body=", does provide the filled out capture template.

So it seems that, when called from Firefox, the start of the URI (i.e. org-protocol://capture) is cut off. The good news (well...) is that the error reproduces in Chrome in exactly the same manner. Any ideas how to resolve this issue?

Thanks in advance!

Here's my setup:

  • Windows 10
  • Emacs 25.3.1
  • Org 9.1.5
  • Firefox 57.03
  • Chrome 63.0.3239.108

These are the capture templates:

 ("p" "Protocol" entry (file+headline 
 		,(concat org-directory "/inbox.org") "Web captures")
 		"* %^{Title}\nSource: %u, %c\n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n\n\n%?")	
 ("L" "Protocol Link" entry (file+headline 
 		,(concat org-directory "/inbox.org") "Web captures")
 		"* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")

And here is the registry file I used to setup org protocol:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\org-protocol]
@="URL:Org Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\org-protocol\shell]

[HKEY_CLASSES_ROOT\org-protocol\shell\open]

[HKEY_CLASSES_ROOT\org-protocol\shell\open\command]
@="\"c:\\Program Files (x86)\\emacs-25.3_1\\bin\\emacsclientw.exe\" \"%1\""

Operation not supported chromium-56.0.2924.87 Fedora 25

I'm trying to solve Operation not supported issue on chromium. If somebody have any thoughts please let me know

Fedora 25 (Workstation Edition) chromium-56.0.2924.87-3.fc25.x86_64

journalctl output:
Mar 28 00:11:25 magnolia.local chromium-browser.desktop[10055]: gio: org-protocol://capture:/p/https%3A%2F%2Fstackoverflow.com%2Fquestions%2F11494232%2Fwhy-is-chrome-browseraction-onclicked-undefined/javascript%20-%20Why%20is%20chrome.browserAction.onClicked%20undefined%3F%20-%20Stack%20Overflow/-%20Use%20variables%20or%20functions%20defined%20by%20their%20extension%27s%20pages%0A: Operation not supported

org-protocol-capture-html support

Hi,

This extension is very nice, I finally got around to trying it, and it works great!

It would be nice if support could be added for https://github.com/alphapapa/org-protocol-capture-html, which would enable the capture of HTML elements, tables, blocks, etc. converted to Org with Pandoc. This would require a few things:

  1. Support other sub-protocols, in this case capture-html. I saw some mention of supporting store-link, etc, so if that is added, this would be easier.
  2. Get the selection differently, depending on the sub-protocol, i.e. it shouldn't be filtered through escapeIt, but should be passed raw so Pandoc can handle it. And it should get the underlying HTML for the selection, not the rendered text.
  3. Perhaps a way to choose different sub-protocols from the right-click menu, or to activate different ones with keyboard shortcuts.

Thanks.

Use store-link instead of org-protocol://capture:/L

Did you know that you can use store-link with org-protocol?

It would be nice to use it (as default or maybe as an option). I could work on this feature.

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

Does not work anymore with org-mode 9.0

It looks like the new-style links available in org-mode 9.0 break this extension.

I now receive the following warning in the Warnings buffer:
Warning (emacs): Please update your org protocol handler to deal with new-style links.

And the following message in Messages:

Greedy org-protocol handler.  Killing client.
No server buffers remain to edit

I have not changed my capture templates which are:

("p" "Protocol" entry (file+headline (concat org-directory "/bookmarks.org") "Inbox") "* %? [[%:link][%:description]] \n  - Captured: %U \n#+BEGIN_QUOTE\n%i\n#+END_QUOTE\n" :immediate-finish t)
("L" "Protocol Link" entry (file+headline (concat org-directory "/bookmarks.org") "Inbox") "* %? [[%:link][%:description]] \n  - Captured: %U" :immediate-finish t)

Thanks for your help.

"There was an error in the Python parsing script." - help wanted!

I tried installing this system on my Mac (MacOs 10.14.6). It sort of worked once, although it gave me some error, and now when I click the icon absolutely nothing happens, so far as I can tell.

I tried going through your debug steps and so far have got to step 3 (I think it is), where I execute

open org-"protocol://capture:/p/a/b"

in a terminal. That gives me a pop up saying

There was an error in the Python parsing script.

But I'm darned if I can find this parsing script! If I could only find it I could probably fix it.

Can you help guide me as to how I might get this working please?

Percent/Url encoding

Hi,

I've setup your nice chrome capture extension on mac osx using EmacsClient.app and spacemacs.
Everything seemed to work except for URLs that include % signs to escape special characters.
(e.g. https://en.wikipedia.org/wiki/Pontryagin%27s_maximum_principle)

When pressing the button of the org-capture-extension in chrome, EmacsClient shortly "starts"/flashes up but there is No reaction in spacemacs (with and without text selected).

This is the output of the chrome developer console:
Capturing the following URI with org-protocol: org-protocol://capture:/L/https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FPontryagi…gin's%20maximum%20principle%20-%20Wikipedia%2C%20the%20free%20encyclopedia

I guess the apostrophe in "Pontryagin**'**s" is a problem.

I tried also directly with emacsclient on the terminal but I couldn't figure out the correct command:
emacsclient "'org-protocol:/capture:/L/https://en.wikipedia.org/wiki/Pontryagin%27s_maximum_principle/Pontryagin's maximum principle "'"
Although this fires up spacemacs...

Can you tell me if this is an issue with the org-capture-extension code or should I escape the %-sign using my capture templates?

Brackets '[' ']' in link description cause broken org-mode link

Thank you for this great extension, it worked out of the box with my config (Debian distro).

I just had some problems with ArXiv.org links (https://arxiv.org/abs/1606.04838 for instance), because page tile:

[1606.04838] Optimization Methods for Large-Scale Machine Learning

contains [, ] brackets.

Using the org-capture-template:

(setq org-capture-templates `(
	
	("L" "Protocol Link" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
        "* %? [[%:link][%:description]]\n")
))

returns broken org-mode link.

I used a function to convert [, ] char into (, ) to fix this:

(defun transform-square-brackets-to-round-ones(string-to-transform)
  "Transforms [ into ( and ] into ), other chars left unchanged."
  (concat 
  (mapcar #'(lambda (c) (if (equal c ?[) ?\( (if (equal c ?]) ?\) c))) string-to-transform))
  )

(setq org-capture-templates `(
	
	("L" "Protocol Link" entry (file+headline ,(concat org-directory "notes.org") "Inbox")
        "* %? [[%:link][%(transform-square-brackets-to-round-ones \"%:description\")]]\n")
))

but I think that there is certainly better/more elegant fix.

Maybe it would be interesting to mention this potential problem in the doc (ArXiv is a widely used site)

Best,
Vincent

Capture all open tabs

Although this is a great effort thus far, it would be even better if you could capture the group of tab's URLs and dump them into org mode. I sometimes have 50+ tabs open and capturing each ones URL individually is not practical.

Captures old highlights too

Thanks for this extension.

I am using Manjaro linux and Emacs 26.3.

Capture works fine when saving links. However when I try to capture quotes it does not seems to clear the memory from the previous capture.

This is what I get, I tried capturing 3 times and the highlighted text seems to just get appended to the old captures.

* 
Captured On: [2020-04-20 mån 01:22]
Source: [2020-04-20 mån], ** sds
Captured On: [2020-04-20 mån 01:18]
Source: [2020-04-20 mån], sds
Captured On: [2020-04-20 mån 01:18]
Source: [2020-04-20 mån], use
 #+BEGIN_QUOTE
Some workers bought rudimentary face shields from a recreation supervisor who purchased a box online for $160. By last week, employees were pleading for help from the government and for donations of personal protective equipment in Facebook posts.

But it was too late.
#+END_QUOTE




 #+BEGIN_QUOTE
But the virus kept finding frail and older residents, and one culprit became clear: The workers themselves were likely spreading it as they moved between rooms and floors, outfitted with little or no protective equipment.
#+END_QUOTE




 #+BEGIN_QUOTE
But it was too late.
#+END_QUOTE


%?

No proper text escaping

Selecting text:

The gist of it is to make your system recognize emacsclient as the handler of org-protocol:// links. In addition, one needs to set up emacs to load org-protocol and to set up capture templates.

Blows my capture up

Firefox: Keyboard shortcut fails first time pressed in each tab

Currently the keyboard shortcut does not work unless the button is physically pressed first. I've got no idea why; related to #19.

I spent some time trying to get it to work without much luck. It's possibly a bug in Firefox, as it seems to work in Chromium with no problems.

Create a version of this application that uses nativeMessaging to communicate with emacsclient

While attempting to whitelist this extension at work recently, it was pointed out to me recently that many Chrome extensions listen to all URLs that Chrome navigates to; in some cases, these URLs are sent to third parties. This may be undesirable from the point of someone who thinks using org-protocol on their local computer doesn't leak any information to third parties. This reviewer suggested using the Chrome nativeMessaging functionality, which allows an extension to execute a script on the user's desktop which reads JSON input on standard input and writes JSON output on standard output.

I'd go about this by following the tutorial app in the nativeMessaging documentation. The commands to open URLs in desktop environments are these:

  • Linux: xdg-open
  • macOS: open
  • Windows: start

Alternatively, you can directly call emacsclient with an org-protocol URL, so the nativeMessaging app may want to default to this option. That would have the bonus of the user not having to set up a protocol handler, which would reduce the friction of setting up this extension.

Allow setting of tags and description when capturing

Hello,

I'm using your extension mainly as a replacement for the built-in bookmarking feature of Firefox. Therefore it would be nice, if it would be possible to set relevant tags and a short description directly in Firefox when I capture a new link. Similar to whats been done in #55.
Some kind of pop-up window would also be useful with regard to unwanted captures (for example when the hotkey is pressed by chance), as you could directly cancel the capturing process instead of having to go to your org-file and delete the unwanted link.

Is the README outdated?

No matter whether there is a selection or not I get a p capture template and the format is not the same as documented:

org-protocol://capture?template=p&url=https%3A%2F%2Fgithub.com%2Fsprig%2Forg-capture-extension&title=sprig%2Forg-capture-extension%3A%20A%20Chrome%20and%20firefox%20extension%20facilitating%20org-capture%20in%20emacs&body=If%20some%20text%20is%20selected%20before%20the%20button%20is%20clicked%2C%20then%20the%20following%20is%20sent%20to%20emacs%3A%0A%0A

org-protocol://capture?template=p&url=https%3A%2F%2Fdeveloper.gnome.org%2Fdesktop-entry-spec%2F&title=Desktop%20Entry%20Specification&body=%25u

Support for general links

Don't know if anyone really wants such a thing, but it seems potentially useful to be able to construct arbitrary links on capture, according to user-specified template

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.