exupero's blog

Obb script to create new Obsidian file from browser URL

In the previous post I showed an obb script to copy the current URL in the browser and paste it as a Markdown link into Obsidian. One other use I've made of obb with Obsidian is to copy the current URL, create a new file, and enter the URL into a modal that appears. I have a few of these for different kinds of URLs to log, such as Jira tickets, pull requests, and design documents. Here's the script for creating a new file for a started ticket:

(let [app (doto (js/Application.currentApplication)
            (as-> $ (set! (.-includeStandardAdditions $) true)))
      se (js/Application "System Events")
      firefox (js/Application "Firefox")]
  (.activate firefox)
  (js/delay 0.25)
  (.keystroke se "l" #js {:using #js ["command down"]})
  (js/delay 0.25)
  (.keystroke se "c" #js {:using #js ["command down"]})
  (js/delay 0.25)
  (.doShellScript app
    "open 'obsidian://new?vault=work&file=WIP%2Fnew%20ticket'")
  (js/delay 1)
  (.keystroke se "v" #js {:using #js ["command down"]})
  (js/delay 0.5)
  (.keyCode se 36))

The modal appears thanks to Templater, which I've configured to use a particular template for new files in the WIP folder; the template includes Templater code to pop up a modal that asks for a URL then passes it to a shell script that fetches additional data about it and returns JSON for the template to use in YAML front matter or creating links in the body of the Markdown file.