Skip to content

Instantly share code, notes, and snippets.

@Metaxal
Last active February 1, 2021 13:40
Show Gist options
  • Save Metaxal/66bfe03ea875100933fea017187c8a1c to your computer and use it in GitHub Desktop.
Save Metaxal/66bfe03ea875100933fea017187c8a1c to your computer and use it in GitHub Desktop.
Copy some hyperlinked text into the clipboard, then use this script to output both the text and the url.
#lang racket/base
(require quickscript
racket/class
racket/list
racket/gui/base)
;; License: [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0) or
;; [MIT license](http://opensource.org/licenses/MIT) at your option.
;;; The clipboard must contain a link copied from a webpage.
;;; The script outputs the selected text and the hyperlink.
(define-script clipboard->text+url
#:label "clipboard->text+url"
(λ (selection)
(define x (send the-clipboard get-clipboard-string 0))
(define str (bytes->string/utf-8 (send the-clipboard get-clipboard-data "text/html" 0)))
(define link (regexp-match #px"href=\"([^\"]*)\" " str))
(format "~a ~s" x (and link (second link)))))
(module url2script-info racket/base
(provide filename url)
(define filename "clipboard2text+url.rkt")
(define url "https://gist.github.com/Metaxal/66bfe03ea875100933fea017187c8a1c"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment