From mboxrd@z Thu Jan 1 00:00:00 1970 From: Anthony Lander Subject: Re: [PATCH] org-mac-link: Improve grabbing behavior for Chrome. Date: Tue, 25 Mar 2014 11:19:32 -0400 Message-ID: References: <1395534192-21594-1-git-send-email-demon386@gmail.com> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c2ba8470e98e04f56fe321 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:53807) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WST9I-0001Xb-QC for emacs-orgmode@gnu.org; Tue, 25 Mar 2014 11:20:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WST9C-0000hk-PV for emacs-orgmode@gnu.org; Tue, 25 Mar 2014 11:20:20 -0400 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:39096) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WST9C-0000hE-8i for emacs-orgmode@gnu.org; Tue, 25 Mar 2014 11:20:14 -0400 Received: by mail-wg0-f46.google.com with SMTP id b13so430868wgh.29 for ; Tue, 25 Mar 2014 08:20:12 -0700 (PDT) In-Reply-To: <1395534192-21594-1-git-send-email-demon386@gmail.com> 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: Muchenxuan Tong Cc: "emacs-orgmode@gnu.org Mode" --001a11c2ba8470e98e04f56fe321 Content-Type: text/plain; charset=ISO-8859-1 Thanks for improving the link grabber! -Anthony On Sat, Mar 22, 2014 at 8:23 PM, Muchenxuan Tong wrote: > * 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 > > > --001a11c2ba8470e98e04f56fe321 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thanks for improving the link grabber!

= =A0 -Anthony


On Sat, Mar 22, 2014 at 8:23 PM, Muchenxuan Tong <demon386@gma= il.com> wrote:
* contrib/lisp/org-mac-link.el (org-as-mac-c= hrome-get-frontmost-url):
=A0 Improve AppleScript used for grabbing information from Chrome. Now
=A0 it's shorter and doesn't require switching to the app. Also, =A0 starting and ending quote are trimmed only when necessary.
---
=A0contrib/lisp/org-mac-link.el | 32 ++++++++++++--------------------
=A01 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"= ;

=A0(defun org-as-mac-chrome-get-frontmost-url ()
=A0 =A0(let ((result (do-applescript
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(concat
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "set oldClipboard to the cli= pboard\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "set frontmostApplication to= path to frontmost application\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "tell application \"Goo= gle Chrome\"\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " activate\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " delay 0.15\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " tell application \"Sy= stem Events\"\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " =A0 =A0 =A0 =A0 keystroke = \"l\" using command down\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " =A0 =A0 =A0 =A0 keystroke = \"c\" using command down\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " end tell\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " delay 0.15\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " set theUrl to the clipboar= d\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " set the clipboard to oldCl= ipboard\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 " set theResult to (get theU= rl) & \"::split::\" & (get name of window 1)\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "end tell\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "activate application (front= mostApplication as text)\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "set links to {}\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "copy theResult to the end o= f links\n"
- =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 "return links as string\n&qu= ot;))))
- =A0 =A0(substring (car (split-string result "[\r\n]+" t)) 1 -1)= ))
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(concat
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"set frontmostApplication to path= to frontmost application\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"tell application \"Google C= hrome\"\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0" =A0 =A0set theUrl to get URL of= active tab of first window\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0" =A0 =A0set theResult to (get th= eUrl) & \"::split::\" & (get name of window 1)\n" + =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"end tell\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"activate application (frontmostA= pplication as text)\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"set links to {}\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"copy theResult to the end of lin= ks\n"
+ =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0"return links as string\n"))= ))
+ =A0 =A0(replace-regexp-in-string "^\"\\|\"$" "&q= uot;
+ =A0 =A0 (car (split-string result "[\r\n]+" t)))))

=A0(defun org-mac-chrome-get-frontmost-url ()
=A0 =A0(interactive)
--
1.9.1



--001a11c2ba8470e98e04f56fe321--