Friday, August 21, 2026

How to open notepad and type with batch file

 @echo off

title Type Text Automation


:: 1. Open Notepad

start "" notepad.exe

echo Waiting for Notepad to open...

timeout /t 2 >nul


:: 2. Create a temporary script to type text

set "VBS_FILE=%temp%\type_text.vbs"


(

echo Set objShell = WScript.CreateObject^("WScript.Shell"^)

echo ' Make sure Notepad is the active window

echo objShell.AppActivate "Notepad"

echo WScript.Sleep 500

echo ' Type the characters

echo objShell.SendKeys "abcd"

) > "%VBS_FILE%"


:: 3. Execute the typing script

cscript //nologo "%VBS_FILE%"


:: 4. Delete the temporary script file

del "%VBS_FILE%"


echo Done!

timeout /t 2 >nul


No comments:

Post a Comment