-
Notifications
You must be signed in to change notification settings - Fork 0
/
chrurl-1.1.el
57 lines (47 loc) · 2 KB
/
chrurl-1.1.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;; chrurl.el --- Insert the URL of the 'topmost' Chrome -*- lexical-binding: t -*-
;; Copyright 2020 by Dave Pearson <davep@davep.org>
;; Author: Dave Pearson <davep@davep.org>
;; Version: 1.1
;; Keywords: hypermedia
;; URL: https://github.com/davep/chrurl.el
;; Package-Requires: ((emacs "25.1"))
;; This program is free software: you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by the
;; Free Software Foundation, either version 3 of the License, or (at your
;; option) any later version.
;;
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
;; Public License for more details.
;;
;; You should have received a copy of the GNU General Public License along
;; with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; chrurl.el provides a simple command that will insert the URL of the
;; "topmost" instance of Google Chrome into the current buffer.
;;
;; Note that, at the moment, this only works on macOS. I seldom work for any
;; sensible time in any other environment so adding other platforms isn't a
;; priority right at the moment.
;;; Code:
(require 'subr-x)
(defvar chrurl-macos "
if application \"Google Chrome\" is running then
tell app \"Google Chrome\" to get URL of active tab of first window
end if
"
"AppleScript code to get the URL from Chrome.")
;;;###autoload
(defun chrurl (&optional markup)
"Insert the URL of the 'topmost' instance of Chrome.
MARKUP is a prefix argument. nil means insert the URL as-is. any
other value means the URL should be inserted wrapped in <URL:...>
markup."
(interactive "*P")
(if-let ((url (string-trim (shell-command-to-string (format "osascript -e '%s'" chrurl-macos)))))
(insert (if markup (format "<URL:%s>" url ) url))
(error "Could not get the URL from Google Chrome")))
(provide 'chrurl)
;;; chrurl.el ends here