Fun with AHK

A place to collect and/or link to AutoHotKey resources for use in Obsidian. Continuing the discussion from AHK repository:

zid = zettelkasten ID
From @crabtree


Send an email directly from inside Obsidian

I blagged the following from the ConnectedText forum. It was written by Manfred Keuhn

` & m:: ;send e-mail
Gui, Add, Edit, W300 vemail,
Gui, Add, Edit, W300 vsubject,
Gui, Add, Edit, W300 R20 vbody,
Gui, Add, Button, Default, Send
Gui, Show
Return,
ButtonSend:
Gui, Submit, NoHide
if email = Email
{
Return,
}
if message = Message
{
Return,
}
else
Run, mailto:%email%?subject=%Subject%&body=%body%
Gui destroy
return

Split the pane vertically and create a new file

@kiriappee on Obsidian forum

#IfWinActive ahk_exe Obsidian.exe
^+n::
Send ^pSplit vertically{Enter}^n
return

Entry form for bibliographical (Book) data

Adapted from the ConnectedText Forum, by @keuhnm. It creates links for the author, the title, and the publisher. The backtick hotkey might be a bit troublesome if you ever do any code highlighting.

` & b::
Gui, Add, Text, x6 y17 w80 h20 , Author:
Gui, Add, Text, x6 y47 w80 h20 , Title:
Gui, Add, Text, x6 y77 w80 h20 , Place:
Gui, Add, Text, x6 y107 w80 h20 , Publisher:
Gui, Add, Text, x6 y137 w80 h20 , Year:
Gui, Add, Edit, x55 y17 w380 h20 vContent1
Gui, Add, Edit, x55 y47 w380 h20 vContent2 
Gui, Add, Edit, x55 y77 w380 h20 vContent3
Gui, Add, Edit, x55 y107 w380 h20 vContent4
Gui, Add, Edit, x55 y137 w180 h20 vContent5 
Gui, Add, Button, x106 y167 w100 h30, Enter ; The label ButtonEnter will be run when the button is pressed.
Gui, Add, Button, x296 y167 w100 h30 , Cancel ; The label ButtonCancel will cancel action but keep script running.
Gui, Show, x350 y182 h210 w461, New Entry
Return ; End of auto-execute section. The script is idle until the user does something.
GuiClose:
   ButtonCancel:
     Gui,Destroy
     Return
   ButtonEnter:
     Gui, Submit  ; Save the input from the user to each control's associated variable.
Gui,Destroy
Send [[%content1%]] (%content5%) *[[%content2%]]*. %content3%: [[%content4%]]`n`n
return

Entry form for bibliographical (Journal ) data
Adapted from the above.

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
#SingleInstance,Force ; Only launch 1 instance of this script.
;~ #Persistent ;Will keep it running...


` & j::
Gui, Add, Text, x6 y17 w80 h20 , Author:
Gui, Add, Text, x6 y47 w80 h20 , Title:
Gui, Add, Text, x6 y77 w80 h20 , Vol-Iss:
Gui, Add, Text, x6 y107 w80 h20 , Journal:
Gui, Add, Text, x6 y137 w80 h20 , Year:
Gui, Add, Text, x226 y137 w80 h20 , Pages:
Gui, Add, Text, x6 y167 w80 h20 , URL:
Gui, Add, Edit, x55 y17 w380 h20 vContent1
Gui, Add, Edit, x55 y47 w380 h20 vContent2 
Gui, Add, Edit, x55 y77 w380 h20 vContent3
Gui, Add, Edit, x55 y107 w380 h20 vContent4
Gui, Add, Edit, x55 y137 w160 h20 vContent5 
Gui, Add, Edit, x275 y137 w160 h20 vContent6 
Gui, Add, Edit, x55 y167 w380 h20 vContent7
Gui, Add, Button, x106 y207 w100 h30, Enter ; The label ButtonEnter will be run when the button is pressed.
Gui, Add, Button, x296 y207 w100 h30 , Cancel ; The label ButtonCancel will cancel action but keep script running.
Gui, Show, x350 y182 h255 w461, New Entry
Return ; End of auto-execute section. The script is idle until the user does something.
GuiClose:
   ButtonCancel:
     Gui,Destroy
     Return
   ButtonEnter:
     Gui, Submit  ; Save the input from the user to each control's associated variable.
Gui,Destroy
Send [[%content1%]] (%content5%) '[[%content2%]]'. *[[%content4%]]*, %content3%, %content6%. %content7%`n`n
return
3 Likes
1 Like

Windows: Copy Path with control+shift+7 and paste it with Link format [Link](file:///…). Also copy Chrome URL and paste it Title

I put some code together and here is the result:

^+7:: ; Ctrl+Shift+7 (/)
Clipboard := “”
Send ^l
while !Clipboard {
Sleep, 50
Send ^c
}
Send {End}
WinGetActiveTitle, title

If !WinActive(“ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe”)
{
;Perform the RegEx find and replace operation,
;where the needle is what we want to replace.
haystack := Clipboard
needle := “\”
replacement := “/”
result := RegExReplace(haystack, needle, replacement)
haystack := result
needle := " "
replacement := “%20”
result := RegExReplace(haystack, needle, replacement)
;Empty the Clipboard
Clipboard =
;Copy the result to the Clipboard.
Clipboard := result
Clipboard := “[” . title . “](file:///” . Clipboard . “)”
;Wait for the Clipboard to fill.
ClipWait
return
}

If WinActive(“ahk_class Chrome_WidgetWin_1 ahk_exe chrome.exe”)
{
Clipboard := “[” . title . “](” . Clipboard . “)”
}
Return