topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 3, 2021, 7:21 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: alias pastefromfile instead of alias paste  (Read 1202 times)

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
alias pastefromfile instead of alias paste
« on: May 07, 2021, 04:36 PM »
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

  • Honorary Member
  • Joined in 2018
  • **
  • Posts: 628
    • View Profile
    • Donate to Member
Re: alias pastefromfile instead of alias paste
« Reply #1 on: May 07, 2021, 09:17 PM »
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

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,129
    • View Profile
    • Donate to Member
Re: alias pastefromfile instead of alias paste
« Reply #2 on: May 08, 2021, 07:51 AM »
Is there an alias that works just like paste %WHATEVER% ... except it takes the contents of %WHATEVER% from a filepath on your local machine?
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 [Select]
  1. ; read string from textfile and paste in active window
  2. FileRead, String, C:\file.txt
  3. Clipboard := String
  4. Send ^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.
« Last Edit: May 08, 2021, 02:16 PM by Nod5 »

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Re: alias pastefromfile instead of alias paste
« Reply #3 on: May 08, 2021, 01:29 PM »
Thanks for the replies folks!

I was hoping to avoid additional external dependencies outside FARR, but these are great suggestions.

Cheers.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,129
    • View Profile
    • Donate to Member
Re: alias pastefromfile instead of alias paste
« Reply #4 on: May 08, 2021, 02:22 PM »
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.

dreftymac

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 17
    • View Profile
    • Donate to Member
Re: alias pastefromfile instead of alias paste
« Reply #5 on: May 10, 2021, 06:14 PM »
Thanks for the Lintalist recommendation. It looks like a well-rounded project and a good productivity booster for folks who are proficient with AHK.

I personally have gone down the Python route for this kind of thing.

For example, I actually have something substantially similar to Lintalist, worked out with YAML/JINJA2/TK.

I do see Lintalist appears to have some distinct advantages in some areas, relative to Python. For example, it is obviously geared toward simpler manipulation of WindowsAPI primitives, which can definitely require a lot more grunt-work from within Python.

In contrast, with Python, there is very little (if anything) that cannot be tweaked to your exact liking. Packages exist for everything under the sun, and you can configure things down to what precise syntax you want to use for snippet placeholders (for example), and what kind of expressions or dynamic values you want to have available to populate them.

This is why pastefromfile in FARR would round things out nicely, since it would permit any kind of inter-process communication where simple textfiles serve as the "pipes" between different applications, and FARR could serve as the general-purpose GUI front-end. Technically, it is already possible, since FARR is so extensible, but one goal is to minimize the amount of "clever workarounds" required.

Anyway, it is always satisfying to see other people's solutions and tools for productivity boosts, all centered around great ideas that you know took some time and thought.

Thanks, therefore, for your time and thought, and informative feedback!


mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 40,676
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: alias pastefromfile instead of alias paste
« Reply #6 on: May 10, 2021, 07:52 PM »
I can certainly add pastefromfile function easily enough.  :up: