Captee

Charles Choi has an application, Captee, in the Mac App store that’s a generalization of my jcs-get-link function. My function inserts an Org link to the currently active page in Safari. I use it constantly when writing blog posts. It may seem like a simple thing but it saves me a huge amount of time.

It’s pretty simple but it uses Apple Script so it only works on the Mac. Here it is:

(defun jcs-retrieve-url ()
  "Retrieve the URL of the current Safari page as a string."
  ;; (org-trim (shell-command-to-string
  ;;   "osascript -e 'tell application \"Safari\" to return URL of document 1'")))
  (do-applescript "tell application \"Safari\" to return URL of document 1"))

(defun jcs-get-link (hostp)
  "Retrieve URL from current Safari page and prompt for description.
With the universal argument, return a link to the host only.
Insert an Org link at point."
  (interactive "P")
  (let* ((link (read-from-minibuffer "Link Description: "))
         (result (jcs-retrieve-url))
         (urlobj (url-generic-parse-url result))
         (host (concat (url-type urlobj) "://" (url-host urlobj))))
    (insert (format "[[%s][%s]]" (if hostp host (org-trim result)) link))))

It would be easy to change this to work with any browser on the Mac.

Choi’s solution is a generalization because it works with any application that supports the Mac Share menu. It can also generate either Org or Markdown markup. For non-Emacs use, it puts the result in the clipboard but inserts it directly into the buffer if you’re using Emacs. On the other hand, you have to switch focus to the application to use the share menu whereas with jcs-get-link you don’t have to leave the comfort of Emacs. If you’re looking for an easy way to insert Org or Markdown links, take a look at Captee.

This entry was posted in General and tagged , . Bookmark the permalink.