-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChrome.el
91 lines (76 loc) · 2.55 KB
/
Chrome.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;;; Chrome.el --- Chrome.app -*- lexical-binding: t; -*-
;; Copyright (C) 2013-2018 Leo Liu
;; Author: Leo Liu <[email protected]>
;; Keywords: tools, processes
;; 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:
;; Control Chrome from Emacs.
;;; Code:
(eval-when-compile (require 'osa))
(require 'cl-lib)
(defcustom Chrome-application-name "Google Chrome Canary"
"Chrome application name."
:type 'string
:group 'osa)
(defun Chrome-tabs ()
(split-string (read (osa "
tell application #{Chrome-application-name}
set allTabs to {}
repeat with w in windows
repeat with x in tabs of w
copy URL of x as text to end of allTabs
end repeat
end repeat
set AppleScript's text item delimiters to {\"----\"}
return allTabs as text
end tell"))
"----"))
(defun Chrome-read-tab ()
(completing-read "Chrome tab: " (Chrome-tabs) nil t))
;;;###autoload
(defun Chrome-reload (&optional tab)
(interactive (and current-prefix-arg (list (Chrome-read-tab))))
(osa "tell application #{Chrome-application-name}
set nil to missing value
if #{tab} is missing value then
tell active tab of front window to reload
else
repeat with t in (first tab of windows whose URL is #{tab})
if t is not missing value then
tell t to reload
end if
end repeat
end if
end tell"))
;;;###autoload
(defun Chrome-browse-url-helper (url prefix &optional background)
(let ((url (substring-no-properties url))
(prefix (substring-no-properties prefix))
(background (if background "true" "false")))
(osa "tell application #{Chrome-application-name}
try
set x to (first tab of front window whose URL starts with #{prefix})
on error
tell front window
set x to make tab
end tell
end try
if x is loading then
tell x to stop
end if
set URL of x to #{url}
if #{background} is \"false\" then
tell x to activate
end if
end tell")))
(provide 'Chrome)
;;; Chrome.el ends here