From mboxrd@z Thu Jan 1 00:00:00 1970 From: Muchenxuan Tong Subject: [PATCH] org-mac-link: Improve grabbing behavior for Chrome. Date: Sun, 23 Mar 2014 08:23:12 +0800 Message-ID: <1395534192-21594-1-git-send-email-demon386@gmail.com> Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35348) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRWm3-0001MD-GC for emacs-orgmode@gnu.org; Sat, 22 Mar 2014 21:00:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WRWCz-00051S-DK for emacs-orgmode@gnu.org; Sat, 22 Mar 2014 20:26:57 -0400 Received: from mail-pb0-x22d.google.com ([2607:f8b0:400e:c01::22d]:36186) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WRWCz-00051M-5x for emacs-orgmode@gnu.org; Sat, 22 Mar 2014 20:24:13 -0400 Received: by mail-pb0-f45.google.com with SMTP id uo5so3931155pbc.18 for ; Sat, 22 Mar 2014 17:24:11 -0700 (PDT) List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Muchenxuan Tong * 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. --- contrib/lisp/org-mac-link.el | 32 ++++++++++++-------------------- 1 file 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) -- 1.9.1