summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuchenxuan Tong <demon386@gmail.com>2014-03-23 08:23:12 +0800
committerBastien Guerry <bzg@altern.org>2014-03-23 09:25:07 +0100
commitcb91729595f896cc7fd9499e2250661c5dd2f49f (patch)
treeb0d233f955ecaed87372038cf6328d6e67f71279
parentb3a10b66febf9cd56b5aff3344627c2b20e08021 (diff)
downloadorg-mode-cb91729595f896cc7fd9499e2250661c5dd2f49f.tar.gz
org-mac-link: Improve grabbing behavior for Chrome.
* contrib/lisp/org-mac-link.el (org-as-mac-chrome-get-frontmost-url): Improve AppleScript used for grabbing information from Chrome. Now it's shorter and doesn't require switching to the app. Also, starting and ending quote are trimmed only when necessary.
-rw-r--r--contrib/lisp/org-mac-link.el32
1 files changed, 12 insertions, 20 deletions
diff --git a/contrib/lisp/org-mac-link.el b/contrib/lisp/org-mac-link.el
index ef46171..d1687e0 100644
--- a/contrib/lisp/org-mac-link.el
+++ b/contrib/lisp/org-mac-link.el
@@ -349,26 +349,18 @@ applications and inserting them in org documents"
(defun org-as-mac-chrome-get-frontmost-url ()
(let ((result (do-applescript
- (concat
- "set oldClipboard to the clipboard\n"
- "set frontmostApplication to path to frontmost application\n"
- "tell application \"Google Chrome\"\n"
- " activate\n"
- " delay 0.15\n"
- " tell application \"System Events\"\n"
- " keystroke \"l\" using command down\n"
- " keystroke \"c\" using command down\n"
- " end tell\n"
- " delay 0.15\n"
- " set theUrl to the clipboard\n"
- " set the clipboard to oldClipboard\n"
- " set theResult to (get theUrl) & \"::split::\" & (get name of window 1)\n"
- "end tell\n"
- "activate application (frontmostApplication as text)\n"
- "set links to {}\n"
- "copy theResult to the end of links\n"
- "return links as string\n"))))
- (substring (car (split-string result "[\r\n]+" t)) 1 -1)))
+ (concat
+ "set frontmostApplication to path to frontmost application\n"
+ "tell application \"Google Chrome\"\n"
+ " set theUrl to get URL of active tab of first window\n"
+ " set theResult to (get theUrl) & \"::split::\" & (get name of window 1)\n"
+ "end tell\n"
+ "activate application (frontmostApplication as text)\n"
+ "set links to {}\n"
+ "copy theResult to the end of links\n"
+ "return links as string\n"))))
+ (replace-regexp-in-string "^\"\\|\"$" ""
+ (car (split-string result "[\r\n]+" t)))))
(defun org-mac-chrome-get-frontmost-url ()
(interactive)