Put multiple lines with special characters into clip using windows batch-file

  • 8 months ago
Comment

ChatGPT
1 / 1

To put multiple lines with special characters into the clipboard using a Windows batch file, you can utilize PowerShell commands within your batch script. Here's an example of how you can achieve this:

batch
@echo off
setlocal

:: Define the text with special characters
set "multilineText=Line 1 with special characters: !@#$%%^&*()"
set "multilineText=!multilineText!^
Line 2 with more special characters: -_=+[]{}|\;:'"",<.>/?"
set "multilineText=!multilineText!^
Line 3 with even more special characters: `~()_+-={}[]|\;:'"",<.>/?"

:: Call PowerShell to set clipboard content
powershell -command "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Clipboard]::SetText('%multilineText%');"

echo Multiline text with special characters has been copied to clipboard.
pause

Replace the content of multilineText with the actual text you want to put into the clipboard. The ^ symbol at the end of each line is used for line continuation within the batch script.

When you run the batch file, it will use PowerShell to set the provided text into the clipboard. You can then paste the content from the clipboard into any application.

Keep in mind that PowerShell may require execution policy changes on some systems. If you encounter issues running the script due to execution policy restrictions, you can temporarily bypass the restriction by running the following command in a PowerShell window (run as administrator):

powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Bypass

Remember to reset the execution policy back to its original state after you're done using it for this purpose:

powershell
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy Restricted

Please note that using PowerShell in a batch script introduces a dependency on PowerShell being available on the system.