exupero's blog
RSSApps

Obb script to copy browser URL and paste Markdown link

I use Obsidian to keep notes on work tasks, and I've found it useful to include links to documentation and other references that I may want to refer back to later but could have hard time finding again. To make it a little easier to insert a Markdown link to the webpage currently open in my browser, I wrote this obb script:

(let [[text] *command-line-args*
      app (doto (js/Application.currentApplication)
            (as-> $ (set! (.-includeStandardAdditions $) true)))
      se (js/Application "System Events")
      firefox (js/Application "Firefox")
      obsidian (js/Application "Obsidian")]
  (.activate firefox)
  (.keystroke se "l" #js {:using #js ["command down"]})
  (js/delay 0.5)
  (.keystroke se "c" #js {:using #js ["command down"]})
  (js/delay 0.2)
  (let [url (.theClipboard app)]
    (.setTheClipboardTo app (str "[" text "](" url ")"))
    (.activate obsidian)
    (js/delay 0.2)
    (.keystroke se "v" #js {:using #js ["command down"]})))

I invoke the script using Alfred. A command such as link these docs copies the current URL from Firefox, switches back to Obsidian and pastes the text [these docs](http://some-url/).

If you have other handy automations for obb or AppleScript, feel free to email me.