Instructions and the script for https://www.youtube.com/watch?v=05wghiNzIj0
EWW - Emacs’ built-in browser is great for many things. Simple use cases include:
- Opening any file on GitHub/GitLab without having to download it
- Log investigation e.g., for GitHub Actions
- Reading PDF - link to a pdf doc opens it in pdf-tools (if installed)
- Bypassing a paywall
This script is about sending URLs from browser to Emacs. With little effort and scripting you can even do some other awesome things (they don’t have to be EWW-related), a few ideas come to mind:
- Display the diff of changes (magit-diff) for a Pull Request URL
- Jump to email (from webmail interface) and open it in mu4e, notmuch, etc.
- Fetch the transcript for a YouTube video and show it in a buffer
And if you think about it, there’s not only URL, you can collect more context and send it over to Emacs to deal with it.
So how do you send current URL from browser to Emacs?
Two ways come to mind: org-protocol
, and on a Mac, you can use a QuickAction
. This doc describes the latter. Share your ideas for the similar thing that works in Linux or Windows.
You need to be running Emacs in daemon mode, so you can use emacsclient
. See Emacs manual to learn more about using Emacs as a server.
- Open
Automator
app New
->Quick Action
-> SelectRun Applescript
from the menu on the left- use the following applescript code:
Note that I use Brave Browser, you can either modify the if
statement to include other browsers, or change it to the main browser of your choice.
on run {input, parameters}
tell application "System Events" to set frontApp to name of first process whose frontmost is true
if (frontApp = "Brave Browser") then -- <- change this to your browser, e.g. Firefox
using terms from application "Google Chrome" -- <- and this
tell application frontApp to set currentTabUrl to URL of active tab of front window
end using terms from
set argsString to "'(funcall-interactively (quote eww) \"" & currentTabUrl & "\" :new-buffer)'"
end if
set EC to "/usr/local/bin/emacsclient --no-wait -e " -- check emacsclient location on disk
-- uncomment next line to troubleshoot, it will display exact command to run from shell (if something goes wrong)
-- display dialog EC & argsString
do shell script EC & argsString
tell application "Emacs" to activate
return input
end run
- When you safe the workflow it should appear in
services
menu.Help -> Search -> Services
- You can bind the key to it in
System Preferences -> Keyboard -> Shortcuts
Here a simplified version for Safari:
Salut