Emacs Capture Anywhere
Effects
Register emacsclient as the org-protocol
handler
For macOS
Start ScriptEditor. Paste the following snippets:
on emacsclient(input)
do shell script "/path/to/your/emacsclient -n -c '" & input & "'"
tell application "Emacs" to activate
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 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>
<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>
For Linux
Please refer to org-protocol handler
Setup handlers in emacs
Add org-capture template
(setq org-capture-templates `(
("p" "Protocol" entry (file+headline "~/Documents/org/notes.org" "Inbox")
"* [[%:link][%:description]] \n\n %u \n #+BEGIN_QUOTE\n%i\n#+END_QUOTE\n %?")
("L" "Protocol Link" entry (file+headline "~/Documents/org/notes.org" "Inbox")
"* %? [[%:link][%:description]] \nCaptured On: %U")
))
Capture on browser
Save as browser bookmark
javascript:window.open('org-protocol://capture?template=p'+ '&url='+encodeURIComponent(window.location.href)+ '&title='+encodeURIComponent(document.title)+ '&body='+encodeURIComponent(window.getSelection()));window.resizeTo(0,0); window.moveTo(0,window.screen.availHeight+10);
Capture on other APPs using hammerspoon
Add the following to your init.lua:
local hyper = {'ctrl', 'option'}
hs.hotkey.bind(hyper, "d",
function ()
local focusedElement = hs.uielement.focusedElement();
if (focusedElement == nil or focusedElement:selectedText() == '' or focusedElement:selectedText() == nil) then
hs.notify.new({title="Capture", informativeText = "No selected text"}):send()
return
end
local focusedWindow = window.focusedWindow()
local url = string.format("org-protocol://capture?template=p&url=HammerSpoon&title=%s&body=%s",
focusedWindow:title(),
focusedElement:selectedText())
hs.notify.new({title= "Capture", informativeText = focusedWindow:title() .. "\n" .. focusedElement:selectedText()}):send()
hs.execute(string.format("open '%s'", url))
end)
Then you can use C-M d
to capture selected text
References
- org-protocol: https://orgmode.org/worg/org-contrib/org-protocol.html
- org-capture-extension: https://github.com/sprig/org-capture-extension
- emacs china: https://emacs-china.org/t/emacs/10367