私人笔记:在macos上配置org-protocol

为实现这个帖子中的功能,

我研究了下 如何在macos上配置org-protocol,在chrome上测试成功

我用的是emacsclient,

配置步骤:

  1. run command below on terminal (打开脚本剪辑器):
open -a /System/Applications/Utilities/Script\ Editor.app

点击新建文稿

  1. copy content below in the Script Editor
on open location this_URL
	do shell script "/usr/local/bin/emacsclient -s \"$HOME/.emacs.d/server/server1\"   \"" & this_URL & "\""
end open location

Save it as Applications (存储为应用程序,not the default Script) File Format and create org-protocol.app under directory: /Applications

you will find info.plist under /Applications/org-protocol.app directory

  1. Open info.plist in org-protocol.app, the structure looks like this:
   <plist>
      <dict>
      ...
      </dict>
   </plist>
  1. Add CFBundleIdentifier snippet below as child of <dict> in info.plist
	<key>CFBundleIdentifier</key>
	<string>com.apple.ScriptEditor.id.org-protocol</string>
	<key>CFBundleInfoDictionaryVersion</key>
	<string>6.0</string>
	<key>CFBundleName</key>
	<string>Org Protocol Handler</string>
	<key>CFBundlePackageType</key>
	<string>APPL</string>
	<key>CFBundleShortVersionString</key>
	<string>1.0</string>
	<key>CFBundleSignature</key>
	<string>aplt</string>
	<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleURLName</key>
			<string>EmacsClientCapture</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>org-protocol</string>
			</array>
		</dict>
	</array>
  1. To register the org-protocol, just double click on the org-protocol.app
  2. config org capture template
(add-to-list 'org-capture-templates
             '("w" "Web Capture" entry
               (file "/tmp/web-captures.org")
               "* %^{Title}\n:PROPERTIES:\n:URL: %:link\n:END:\n\n%i\n%?"
               :immediate-finish t
               :kill-buffer t
               :prepend t))
  1. verify if shell script in org-protocol.app works by clicking bookmark on chrome which is a javascript

    a) chrome will ask you if you want to open org-protocol.app

    b) emacs also will have some action

    c) 验证emacs, 我用的是emacsclient

emacsclient -s $HOME/.emacs.d/server/server1 "org-protocol://capture?template=w&url=https%3A%2F%2Forgmode.org%2Fworg%2Forg-contrib%2Forg-protocol.html%23org3f06679&title=org-protocol.el%20%E2%80%93%20Intercept%20calls%20from%20emacsclient%20to%20trigger%20custom%20actions&body=After%20installing%20EmacsClient.app%20you%20should%20then%20%5B%5Bhttps%3A%2F%2Forgmode.org%2Fworg%2Forg-contrib%2Forg-protocol.html%23org3f06679%5D%5BVerify%20the%20installation%5D%5D.%20Once%20verified%2C%20you%20can%20begin%20%5B%5Bhttps%3A%2F%2Forgmode.org%2Fworg%2Forg-contrib%2Forg-protocol.html%23orgf13b7a9%5D%5BUsing%20org-protocol%5D%5D"

参考文献:

  1. GitHub - aaronbieber/org-protocol-handler: An OS X application that handles org-protocol:// links.
  2. GitHub - xuchunyang/setup-org-protocol-on-mac: Setting Up org-protocol on Mac
  3. org-protocol.el – Intercept calls from emacsclient to trigger custom actions
2 个赞

有点费劲,不如直接用 GitHub - yibie/Copy-as-org-mode-chrome: This WebExtension is a Chrome version of Copy as Org-Mode.

这样比较稳定,比较少受系统 API 的变动影响。

1 个赞

org-protocol 的用处不止这个,比如说通过浏览器书签保存 roam 节点,通过 zetora 把网页论文存到 ebib 中。

嗯,我单纯指保存网页这一情景。org-protocol 是很强大的工具。