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.
This commit is contained in:
parent
b3a10b66fe
commit
cb91729595
|
@ -349,26 +349,18 @@ applications and inserting them in org documents"
|
||||||
|
|
||||||
(defun org-as-mac-chrome-get-frontmost-url ()
|
(defun org-as-mac-chrome-get-frontmost-url ()
|
||||||
(let ((result (do-applescript
|
(let ((result (do-applescript
|
||||||
(concat
|
(concat
|
||||||
"set oldClipboard to the clipboard\n"
|
"set frontmostApplication to path to frontmost application\n"
|
||||||
"set frontmostApplication to path to frontmost application\n"
|
"tell application \"Google Chrome\"\n"
|
||||||
"tell application \"Google Chrome\"\n"
|
" set theUrl to get URL of active tab of first window\n"
|
||||||
" activate\n"
|
" set theResult to (get theUrl) & \"::split::\" & (get name of window 1)\n"
|
||||||
" delay 0.15\n"
|
"end tell\n"
|
||||||
" tell application \"System Events\"\n"
|
"activate application (frontmostApplication as text)\n"
|
||||||
" keystroke \"l\" using command down\n"
|
"set links to {}\n"
|
||||||
" keystroke \"c\" using command down\n"
|
"copy theResult to the end of links\n"
|
||||||
" end tell\n"
|
"return links as string\n"))))
|
||||||
" delay 0.15\n"
|
(replace-regexp-in-string "^\"\\|\"$" ""
|
||||||
" set theUrl to the clipboard\n"
|
(car (split-string result "[\r\n]+" t)))))
|
||||||
" 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)))
|
|
||||||
|
|
||||||
(defun org-mac-chrome-get-frontmost-url ()
|
(defun org-mac-chrome-get-frontmost-url ()
|
||||||
(interactive)
|
(interactive)
|
||||||
|
|
Loading…
Reference in New Issue