├── README.org
└── org-protocol.user.js
/README.org:
--------------------------------------------------------------------------------
1 | * Setting Up org-protocol on Mac
2 |
3 | [[http://orgmode.org/worg/org-contrib/org-protocol.html#orgheadline6][org-protocol.el – Mac OS X setup]] doesn't work anymore according to [[https://github.com/neil-smithline-elisp/EmacsClient.app/issues/3][Issue #3 ·
4 | neil-smithline-elisp/EmacsClient.app]].
5 |
6 | ** Step 1. Create an application
7 |
8 | - Launch the Script Editor application and create a new document
9 | - Copy-and-paste the following code into the new document
10 | - Run =where emacsclient= in cli to get the path to =emacsclient= on your system
11 | - Change "/path/to/your/emacsclient" to the result of =where emacsclient=
12 | - Save it in /Application/ (not the default /Script/) File Format as
13 | =org-protocol.app=
14 |
15 | #+BEGIN_SRC applescript
16 | on open location this_URL
17 | do shell script "/path/to/your/emacsclient \"" & this_URL & "\""
18 | tell application "Emacs" to activate
19 | end open location
20 | #+END_SRC
21 |
22 | ** Step 2. Configure the application
23 |
24 | - Navigate to the application (i.e., =org-protocol.app=) in the Finder, then
25 | right-click on it and select =Show Package Contents=. Now go into the
26 | =Contents= folder and open =Info.plist=
27 | - Add the following code to the file, making sure to keep all existing
28 | key/string pairs intact:
29 |
30 | #+BEGIN_SRC xml
31 | CFBundleURLTypes
32 |
33 |
34 | CFBundleURLName
35 | org-protocol handler
36 | CFBundleURLSchemes
37 |
38 | org-protocol
39 |
40 |
41 |
42 | #+END_SRC
43 |
44 | ** Step 3. Install the protocol
45 |
46 | To register the protocol, just click on the =org-protocol.app=.
47 |
48 | ** Step 4. Test your results
49 |
50 | See http://orgmode.org/worg/org-contrib/org-protocol.html#orgheadline8
51 |
52 | * Notes
53 |
54 | ** Emacs doesn't activate?
55 |
56 | I use graphical Emacs and start Emacs server from there, however after clicking
57 | some org-protocol link, Emacs doesn't activate. I don't know the cause. If you
58 | encounter the same issue AND don't like it, you can try this instead
59 |
60 | #+BEGIN_SRC applescript
61 | on open location this_URL
62 | do shell script "/usr/local/bin/emacsclient \"" & this_URL & "\" && open -a Emacs"
63 | end open location
64 | #+END_SRC
65 |
66 | ** User Script
67 |
68 | On web browser, besides bookmarklets, you can also use User Script, for example,
69 | [[./org-protocol.user.js]] binds two keys to Org: store-link and Org: capture.
70 |
--------------------------------------------------------------------------------
/org-protocol.user.js:
--------------------------------------------------------------------------------
1 | // ==UserScript==
2 | // @name org-protocol
3 | // @namespace https://github.com/xuchunyang/setup-org-protocol-on-mac
4 | // @version 0.0
5 | // @description Use Alt + l for Org: store-link and use Alt + o for Org: capture
6 | // @author Chunyang Xu
7 | // @match *://*/*
8 | // @grant none
9 | // ==/UserScript==
10 |
11 | (function() {
12 | 'use strict';
13 | document.addEventListener('keydown', function(e) {
14 | // Alt + l
15 | if (e.keyCode == 76 && !e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
16 | window.location = 'org-protocol://store-link://'+encodeURIComponent(document.location.toString())+'/'+encodeURIComponent(document.title.toString());
17 | }
18 | // Alt + o
19 | if (e.keyCode == 79 && !e.shiftKey && !e.ctrlKey && e.altKey && !e.metaKey) {
20 | var url = document.location.toString();
21 | var title = document.title.toString();
22 | var selection = window.getSelection();
23 | var org_capture_url = 'org-protocol://capture://t/'+encodeURIComponent(url)+'/'+encodeURIComponent(title)+'/'+encodeURIComponent(selection);
24 | window.location = org_capture_url;
25 | }
26 | }, false);
27 |
28 | })();
29 |
--------------------------------------------------------------------------------