You need to install AHK then follow this instruction to create new script.
Then after you activate the script, you press ctrl+shift+V to paste the text with formatting removed.
Thanks for your quick reply. I’m familiar with the basics of AHK, though that info is definitely useful to a new user.
What I didn’t realize is that the script executes upon pasting, rather than after. Haha.
Still, the solution I’m looking for is to retain the formatting (i.e. If I have made a numbered list, I want those numbers to stay), but simply to remove the extra lines. I tried removing everything in your script except the second part (; Remove all blank lines from text…), but that didn’t work for me.
I guess I am still a noob when it comes to AHK, so could you help me refine the code a bit to work with what I need? Or could you give me some pointers?
Actually I don’t know much about coding
It took a while for me to google this script.
I made a small revision to delete single empty line:
^!Space::
clipboard =
Send, ^a
Send, ^c
ClipWait
ClipBoard := RegExReplace(ClipBoard, "\R(?=\R{1,})") ;
sleep 100
Send, ^v
return
Hope it help you.
Hi Guys,
I wanted to create a little AHK macro for myself, but I have a problem with the basic functionality - it seems I cannot copy selected text / paste to Obsidian.
The functionality I am after, which works OK in Notepad++ is here (select text and make it a link)
In obsidian, nothing happens - when inspecting, turns out that I cannot even copy or paste to Obsidian using AHK (yes, in Edit mode:) ). Regular copy/paste works OK.
The script I have is this
!+q::
Link := clipboard
Send, ^c
Description := clipboard
clipboard = %Description%
Send ^v
clipboard = %Link% ;restore
SoundBeep 100,400
return
There are problems with copy pasting with ahk I don’t know why it is that way. I use this code to make sure copying happen:
Clipboard := ""
Loop, {
SendInput, ^c
ClipWait, 0.5
If (ErrorLevel = 0)
Break
}
Also , It’s kinda redundant. It plugin just does that:
Hi,
I’m a really newbie in AHK and I need some help to active 2 hostrings for my dqily note’s template.
I created 2 hotstrings:
“::dd” for the note’s title:
:*:::d:: ;
#IfWinActive ahk_exe Obsidian.exe
FormatTime, CurrentDateTime, dddd dd MMMM yyyy ;
SendInput %CurrentDateTime%
return
And “::a” for the “breadcum trail” (Alfred Snippet for @mitzimbj's Daily Notes Breadcrumb Trail)
:*:::: a:: ;
#IfWinActive ahk_exe Obsidian.exe
yest = %a_now%
yest += -1, days
FormatTime, yest, %yest%, yyyyMMdd
today = %a_now%
today += +1, days
FormatTime, today, %today%, yyyyMMdd
SendInput [[%yest%|Yesterday]] - [[%today%|Tomorrow]]
return
I create a template in my obsidian with these 2 hotstrings for my daily note
Otherwise, when I create the note (with the template) the hotstrings are not been remplaced (I guess because i didn’t “write” them)
How can I fix it?
Thanks
Has anyone got autohotkey code highlighting in obsidian?
In the manual appears this link Prism, but when I use autohotkey it doesn’t work, with js (javascript) it works fine.
Can someone help me to make a script that wraps highlighted text into a tag? Now I have this (found on the web)
!=::WrapClipText("<span style='color:yellow'>", "</span>")
WrapClipText(Left,Right)
{
ClipSaved := ClipboardAll
Clipboard =
send ^c
Clipboard = %Left%%clipboard%%Right%
send ^v
Clipboard := ClipSaved
ClipSaved =
}
But I’d like to use this color blocks, so the highlighted text has to be wrapped into:
and I can’t get it to work. Any help is welcome, thanks!
I’m not an AHK hero, but I would do it this way:
!=::
ClipSaved := ClipboardAll
Clipboard =
send ^c
clipboard =
(
``````note-brown-background
%clipboard%
``` ```
)
send ^v
Clipboard := ClipSaved
ClipSaved =
Maybe there is a better way, but this works.
Important: in line 9 (under %clipboard%
)`, the 6 backticks have to be written without a space in the middle. I had to insert the space because of the editor in this forum.
Works like a charm, thanks for helping!
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
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)
How it works
- Launch
Obsidian Search.ahk
- Select a vault (with down arrows or the first letter in the vault name)
- Tab into the search field and enter search terms
- Hit enter to open Obsidian and perform the search
- Hit
ESC
to escape out of the search interface.