I have a hotkey to open a specific notes.txt file that I always use for quick notes. To make it more convenient I have it set up so when it starts, automatically the 'Enter' key is send twice and then once ^Home. This way you can immediatly start typing on the top of the file for a fresh note, separated from earlier made notes by 1 break in between.
The problem is that sometimes there might already be 1 or 2 breaks at the top of the file. It gets messy if then automatically there is even more breaks added. I'd like to detect wether there is already a break, or 2 breaks and depending on that either send the right amount of 'Enter' presses or none at all. Anyone know how I can do this?
Detect empty line in an open Notepad file Topic is solved
Re: Detect empty line in an open Notepad file
Checking if the line length of the 1st and/or 2nd line = 0 ?
-
- Posts: 5
- Joined: 27 Jan 2022, 14:44
Re: Detect empty line in an open Notepad file Topic is solved
Code: Select all
; 1st line
; 2nd line
#SingleInstance, Force
i:=0
FileReadLine, ln1,% A_ScriptName, 1
FileReadLine, ln2,% A_ScriptName, 2
StrLen(ln1)=0 ? i++ : i
StrLen(ln2)=0 ? i++ : i
MsgBox % "Number of line breaks to add:`t" . 2-i
ExitApp
-
- Posts: 5
- Joined: 27 Jan 2022, 14:44
Re: Detect empty line in an open Notepad file
@BoBo Awesome, thnks!
Re: Detect empty line in an open Notepad file
Code: Select all
; 1st line
; 2nd line
#SingleInstance, Force
SetBatchLines -1
i:=0
Loop 2
{ FileReadLine, ln,% A_ScriptName,% A_Index
StrLen(ln)=0 ? i++ : i
}
Loop % 2-i
Send {Enter}
Send {Ctrl Down}{Home}{Ctrl Up}
ExitApp