DonationCoder.com Software > Find And Run Robot
alias pastefromfile instead of alias paste
dreftymac:
Greetings!
## Question
Is there an alias that works just like paste %WHATEVER% ... except it takes the contents of %WHATEVER% from a filepath on your local machine?
Something like pastefromfile %FILEPATH_HERE% ?
Something like pastefromfile c:\docs\temp\mytemporary_text_file.txt ?
## Rationale
The rationale for this request: paste works great for single-line-only text, but this request is looking for something that can take any arbitrary multi-line-string that lives in a file somewhere on the local machine.
KodeZwerg:
Does this fit?
It is a batch file that reads file text.txt and put it into %var% for your use.
Modify [ set file="test.txt" ] to your needs.
Modify [ var ] to your needs.
Create a new file with extension .bat or .cmd and copy/paste following code:
--- ---@echo off
setlocal enableDelayedExpansion
set LF=^
:: Two blank lines above needed for definition of LF - do not remove
set file="text.txt"
set "var="
for /f %%N in ('find /c /v "" ^<%file%') do set lineCnt=%%N
<%file% (
for /l %%N in (1 1 %lineCnt%) do (
set "ln="
set /p "ln="
set "var=!var!!ln!!lf!"
)
)
set var
Now you have %var% filled with content of "text.txt"
If you want to use it within a program, best practice would be to insert on a new line [ CALL "c:\path\app.exe" ] at bottom.
Nod5:
Is there an alias that works just like paste %WHATEVER% ... except it takes the contents of %WHATEVER% from a filepath on your local machine?
-dreftymac (May 07, 2021, 04:36 PM)
--- End quote ---
Not currently I think. FARR does have the built in alias command fileresults which reads the contents of a text file. But I don't recall any FARR method to use what it reads as a variable for a subsequent paste command.
We could ask mouser to add such a variable to FARR though. (It could then be named %lastfileresults%, similar to how the alias command appcap stores its return value in %lastappcap%)
In the meantime you can use an external helper script for this. Here is a simple AutoHotkey example
--- Code: Autohotkey ---#NoEnv#SingleInstance Force; read string from textfile and paste in active windowFileRead, String, C:\file.txtClipboard := StringSend ^v
Save the script as ReadPaste.ahk and use an alias result line like this
--- ---read string from .txt and paste in active window | C:\folder\ReadPaste.ahk
A more advanced version could pass a regex pattern from the FARR alias as parameter to the script, for example to select another text file to read and paste from.
dreftymac:
Thanks for the replies folks!
I was hoping to avoid additional external dependencies outside FARR, but these are great suggestions.
Cheers.
Nod5:
I should also mention that if you're looking to paste a lot of different multiline strings then Lintalist is a good standalone tool. The landing page is a bit daunting but it is easy to use once you get going. There's a DC post for it here.
Navigation
[0] Message Index
[#] Next page
Go to full version