Fun with AHK

Anyone successful in getting the main notetaking window activated using AHK? The open vault window is the one that’s getting brought up by AHK every time I invoke WinRestore.

; Launch Obsidian Ctrl + Shift + (with consideration to multiple computers)

^+`::

PathToApp = C:\Users%A_UserName%\AppData\Local\Obsidian ; add this workaround because FileExist does not evaluate %A_xxx% variables

Process, Exist, “Obsidian.exe” ; Sets ErrorLevel variable to processID

if(ErrorLevel)

{

if(WinActive("ahk_exe Obsidian.exe"))

{

    ; WinMinimize, ahk_exe "Obsidian.exe"

    WinMinimize, Title, "Obsidian.exe"

}

else

{

    ;WinActivate, ahk_exe "Obsidian.exe"

    ;WinRestore, ahk_exe "Obsidian.exe"

    WinActivate, ahk_exe "Obsidian.exe"

    WinRestore, ahk_exe "Obsidian.exe"

}

}

else

{

if(FileExist(PathToApp))

{

    Run "C:\Users\%A_UserName%\AppData\Local\Obsidian\Obsidian.exe"

}

else

{

    MsgBox Check if Obsidian is installed.

}

}

return
`

I have a script for activating a specific vault, you can check them out, I am not very good with AHK, I can’t at this point explain anything else.

; This will activate obsidian, if not already open, it will open it & run the command for quick add plugin.
; This is one hotkey which I am able to get to work every time in any location whatsoever
^q::
WinActivate, i) Obsidian
Run “obsidian://advanced-uri?vault=my_vault_name_here&commandname=QuickAdd: Run QuickAdd”
return

; It will activate it & run the command for quick capture to daily notes.
; Whenever Chrome is active, this doesn’t seem to work all the time.
^Capslock::
Send, !o
Send, ^+d
return

; It will activate it & run the command for quick capture to workbench
; Whenever Chrome is active, this doesn’t seem to work all the time.
^!x::
Send, !o
Send, ^+x
return

; This will activate the obsidian window & if not open it will open obsidian & activate it
!o::
WinActivate, i) Obsidian
Run “obsidian://advanced-uri?vault=my_vault_name_here”
return

4 Likes

This is great. Thanks so much @Nihit !

1 Like

I like that this thread exists! I’d like to see more

I made a script to add and substract from a selected YYYY-MM-DD date, but if I keep the key down it can get unstable and break, any idea how to make it more stable? I what should I call at the start of the code to help with that?

#NoEnv                      ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn                     ; Enable warnings to assist with detecting common errors.
#SingleInstance FORCE       ; Skip invocation dialog box and silently replace previously executing instance of this script.
SendMode Input              ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
FileEncoding , UTF-8

Capslock & =::
send, ^c
InputVar := Clipboard
send % AddADay(InputVar)
sleep 50
send, {ShiftDown}{left}{left}{left}{left}{left}{left}{left}{left}{left}{left}{ShiftUp}
return

Capslock & -::
send, ^c
InputVar := Clipboard
send % SubADay(InputVar)
sleep 50
send, {ShiftDown}{left}{left}{left}{left}{left}{left}{left}{left}{left}{left}{ShiftUp}
return


AddADay(startdate)
{
StringSplit, splitdate, startdate, -
ymdhms:=splitdate1 splitdate2 splitdate3 "000000"
EnvAdd, ymdhms, 1, days
FormatTime, newdate, %ymdhms%, yyyy-MM-dd
return newdate
}

SubADay(startdate)
{
StringSplit, splitdate, startdate, -
ymdhms:=splitdate1 splitdate2 splitdate3 "000000"
EnvAdd, ymdhms, -1, days
FormatTime, newdate, %ymdhms%, yyyy-MM-dd
return newdate
}

Do you mean you’d like to trigger the hotkey only once even you press down the button for long?

no i wanted to just hold it down and it keep doing what he supposed to until i stop pressing the key , i was just forgetting to use Clipwait command. now it is working just i described

I made a simple script that opens the current pane in a new window, minimizes the original main window, anchors the new window to the forefront, and resizes it. This might be useful on a PC with a small monitor to take some notes while viewing other windows such as a browser. I’m a novice AHK user so I’m not sure if it’s grammatically correct, but if someone could try to get it to work correctly in your obsidian that would be great.

#IfWinActive ahk_class Chrome_WidgetWin_1
^q::							; hotkey for this script
	WinGetActiveTitle,ObsTitle	
	Send, ^+p					; hotkey for 'Open current pane in new window' (ctrl+shift+p in my case)
	Sleep, 50
	WinActivateBottom,%ObsTitle% ahk_class Chrome_WidgetWin_1
	Sleep, 50
	Send, #{Down}				; hotkey for minimize the active window (Windows) 
	Sleep, 50
	Send, ^+l					; hotkey for 'Toggle window always on top' (ctrl+shift+l in my case)
	WinMove,A,,,,600,800		; size of new pop-out window (x:600,y:800 in this case)
1 Like

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.
2 Likes