【AHK】在Obsidian中以选定日期生成链接

定义一个热键 ctrl+q 会显示一个日历,然后根据选择日期 生成一个链接

#IfWinActive ahk_exe Obsidian.exe
^q::
answer := Dialog("请选择一个日期,本工具会以wiki链接形式输出", "good")
send [[%answer%]]
return
Gui, Add, MonthCal, vMyCalendar gButton
Gui, show
Dialog(Question, DefaultValue := "") {
    
    
    return new Dialog(Question, DefaultValue).Wait()
}
class Dialog
{
    
    
    __New(Question, DefaultValue) {
    
    
        Gui, New, +hwndhGui +LabelDialog.On_, Dialog
        this.hwnd := hGui
        Gui, Add, Text,, % Question
     
;        Gui, Add, MonthCal, hwndhEdit vMyCalendar gButton
        Gui, Add, MonthCal, hwndhEdit
        this.hEdit := hEdit
        Gui, Add, Button, gDialog.On_ButtonSendAnswer, 确定
        this.SaveStatus := False
        Gui, Show, w400 h400
        Dialog.Instances[hGui] := this
    }
    
    On_Close() {
    
    
        MsgBox, 4, % " ", Do you want to close the window?
        IfMsgBox, No
            Return 1
        Dialog.RemoveInstance(A_Gui)
    }

    On_ButtonSendAnswer() {
    
    
        this := Dialog.Instances[A_Gui]
        this.SaveStatus := True
        Dialog.RemoveInstance(this.hwnd)
        Gui, Cancel
    }
 
    RemoveInstance(hwnd) {
    
    
        Dialog.Instances.Delete(hwnd)
    }
 
    Wait() {
    
    
        dhw := A_DetectHiddenWindows
        DetectHiddenWindows, Off
        WinWaitClose, % "ahk_id " this.hwnd
        DetectHiddenWindows, % dhw

        If !this.SaveStatus
          Return "not saved"
        GuiControlGet, value,, % this.hEdit
        return value
    }

    __Delete() {
    
    
        Gui, % this.hwnd ":Destroy"
    }
}
#if

猜你喜欢

转载自blog.csdn.net/liuyukuan/article/details/121766421
AHK