I think you can do something like this:

(defun get-description ()
  (interactive)
  (let ((link (org-element-context)))
    (message (buffer-substring (org-element-property :contents-begin link)
      (org-element-property :contents-end link)))))

John

-----------------------------------
Professor John Kitchin (he/him/his)
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803


On Fri, Aug 13, 2021 at 7:12 PM Rodrigo Morales <moralesrodrigo1100@gmail.com> wrote:

* The question

Let's say I have the following link

#+BEGIN_SRC org
This is a sentence [[foo][bar]]. This is another sentence.
#+END_SRC

How to programmatically get the description of the link (i.e. =bar=)?

* Additional information

I've tried using =org-element-context=. The following sexp was
executed when the cursor was on the link which was presented above.

#+BEGIN_SRC text
ELISP> (with-current-buffer "main.org" (org-element-context))
#+END_SRC

#+BEGIN_SRC text
(link
 (:type "fuzzy" :path "foo" :format bracket :raw-link "foo" :application nil :search-option nil :begin 1 :end 15 :contents-begin 8 :contents-end 13 :post-blank 0 :parent
        (paragraph
         (:begin 1 :end 16 :contents-begin 1 :contents-end 16 :post-blank 0 :post-affiliated 1 :parent nil))))
#+END_SRC

and =org-element-at-point=. The following sexp was executed when the
cursor was on the link which was presented above.

#+BEGIN_SRC text
ELISP> (with-current-buffer "main.org" (org-element-at-point))
#+END_SRC

#+BEGIN_SRC text
(paragraph
 (:begin 1 :end 16 :contents-begin 1 :contents-end 16 :post-blank 0 :post-affiliated 1 :parent nil))
#+END_SRC

but neither of those get the description of the link as metadata.