* [PATCH] org-mac-link: Improve grabbing behavior for Chrome.
@ 2014-03-23 0:23 Muchenxuan Tong
2014-03-23 8:25 ` Bastien
2014-03-25 15:19 ` Anthony Lander
0 siblings, 2 replies; 3+ messages in thread
From: Muchenxuan Tong @ 2014-03-23 0:23 UTC (permalink / raw)
To: emacs-orgmode; +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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] org-mac-link: Improve grabbing behavior for Chrome.
2014-03-23 0:23 [PATCH] org-mac-link: Improve grabbing behavior for Chrome Muchenxuan Tong
@ 2014-03-23 8:25 ` Bastien
2014-03-25 15:19 ` Anthony Lander
1 sibling, 0 replies; 3+ messages in thread
From: Bastien @ 2014-03-23 8:25 UTC (permalink / raw)
To: Muchenxuan Tong; +Cc: emacs-orgmode
Muchenxuan Tong <demon386@gmail.com> writes:
> * 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.
Applied, thanks!
--
Bastien
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] org-mac-link: Improve grabbing behavior for Chrome.
2014-03-23 0:23 [PATCH] org-mac-link: Improve grabbing behavior for Chrome Muchenxuan Tong
2014-03-23 8:25 ` Bastien
@ 2014-03-25 15:19 ` Anthony Lander
1 sibling, 0 replies; 3+ messages in thread
From: Anthony Lander @ 2014-03-25 15:19 UTC (permalink / raw)
To: Muchenxuan Tong; +Cc: emacs-orgmode@gnu.org Mode
[-- Attachment #1: Type: text/plain, Size: 2857 bytes --]
Thanks for improving the link grabber!
-Anthony
On Sat, Mar 22, 2014 at 8:23 PM, Muchenxuan Tong <demon386@gmail.com> 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
>
>
>
[-- Attachment #2: Type: text/html, Size: 3813 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-25 15:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-23 0:23 [PATCH] org-mac-link: Improve grabbing behavior for Chrome Muchenxuan Tong
2014-03-23 8:25 ` Bastien
2014-03-25 15:19 ` Anthony Lander
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).