Launch vault and quick search with AutoHotkey

I also multiple Obsidian vaults. I also use a combination of AutoHotKey and Everything for Windows as a keyboard-focused application launcher (similar to Quicksilver or Alfred on OSX). For the last year or so I’ve been refining an Obsidian launcher and quick-search function. Now that it has been stable for a few months, I thought someone else might find it useful. (It’s basically just a GUI for selecting and running different Obsidian URIs. So it’s not clever, just useful.)

How it works

  1. Launch Obsidian Search.ahk
  2. Select a vault (with down arrows or the first letter in the vault name)
    image
  3. Tab into the search field and enter search terms
    image
  4. Hit enter to open Obsidian and perform the search
  • Hit ESC to escape out of the search interface.

One nice feature of this approach is that you can set custom search defaults for each search option. For example, the default search for my work vault omits any “archived” notes (the search always includes -path:"[My Archive Folder]"). That saves some re-typing.

Obsidian Search.ahk

#NoEnv  ; Standard setting recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings for troubleshooting assistance.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; Search Obsidian vaults

; Declare variables
;  Not strictly necessary, but if a previous run failed to perform garbage collection this sets the stage properly.
search_term := ""
vault_select := ""

; Build and display the search interface
  Gui, New, , Obsidian_Search
  Gui, Add, Text, , Select a vault and enter search:

  ; Render input fields
  ;  Each DropDownList option represents a different search you might want to perform
  Gui, Add, DropDownList, Vvault_select W100 section, Personal|Work|Work Archive|[ETC]
  Gui, Add, Edit, Vsearch_term R1 -Multi W450 ys, 
  Gui, Add, Button, Default xs section, &OK
  Gui, Add, Button, ys, &Cancel

  ; Render the window
  Gui, Show, W580, Obsidian Search
  return

ButtonOK:
  Gui, Submit     ; Save each input to the corresponding variable and run the Switch function

  ; Create a case for each DropDownList option you created above
  ;  For each case, `Run` the query URI for the search you want to perform
  Switch vault_select {
    Case "Personal":
      Run, obsidian://search?vault=Personal`%20Knowledgebase&query=%search_term%
    Case "Work":
      Run, obsidian://search?vault=Work`%20Knowledgebase&query=%search_term%`%20-path:`%22Archive`%22
    Case "Work Archive":
      Run, obsidian://search?vault=Work`%20Knowledgebase&query=%search_term%`%20path:`%22Archive`%22
    Case "[ETC]":
      MsgBox, This vault does not exist yet.
    Default:
      MsgBox Not sure how you got here. Select a real vault next time.
  }

  ; MsgBox used for testing and bugfixes
  ; MsgBox Vault: %vault_select%, Search: %search_term%
  ExitApp
return

ButtonCancel:
GuiClose:
GuiEscape:
  ExitApp
return
1 Like