Passing selected text from web or from clipboard as a parameter to TC search function

English support forum

Moderators: white, Hacker, petermad, Stefan2

Post Reply
Box333
Junior Member
Junior Member
Posts: 13
Joined: 2023-02-02, 14:50 UTC

Passing selected text from web or from clipboard as a parameter to TC search function

Post by *Box333 »

Hello Everybody,

it often happens that, before you download a picture, a document or a song, you first want to check, whether you already have that or a similar file on your hard disk.

Unfortunately, I have not yet found a parameter that would transfer the clipboard content to the TC search function or would automatically insert the searched text into the "Search for:" field or pass it as an argument to a TC command.

I use the browser plugin ]Search from popup or context menu (https://addons.mozilla <dot> org/de/firefox/addon/searchfrompopuporcontextmenu), which can be used to pass selected text to a search engine or a local application.

Does anyone have an idea, how to pass a marked text from the web to the TC search function in a simple way, i.e. without AHK, without Everything and without saving it to a list first (because you always search for a single filename)?

Thank you in advance for your ideas

Clickable URL disabled by Moderator.

Same thread in German > https://ghisler.ch/board/viewtopic.php?t=78380
Fla$her
Power Member
Power Member
Posts: 2299
Joined: 2020-01-18, 04:03 UTC

Re: Passing selected text from web or from clipboard as a parameter to TC search function

Post by *Fla$her »

2Box333
The logic of TC is devoid of debugging functions when solving such tasks, which is why resort to automation tools, if not external like AHK, then built-in (bat+wget/curl/etc, vbs/js, PoSh).
For example, I wrote myself a vbs code for downloading via links from the clipboard a long time ago.
Overquoting is evil! 👎
User avatar
beb
Senior Member
Senior Member
Posts: 434
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Passing selected text from web or from clipboard as a parameter to TC search function

Post by *beb »

An example of how to get the clipboard content and turn it into a variable (within cmd; which I've been using for wget/yt-dlp downloads):

Code: Select all

:: Get url from the clipboard
for /f "delims=" %%i in ('mshta "javascript:var x=clipboardData.getData('text');if(x) new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).Write(x);close();"') do set url=%%i
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
User avatar
Stefan2
Power Member
Power Member
Posts: 4155
Joined: 2007-09-13, 22:20 UTC
Location: Europa

Re: Passing selected text from web or from clipboard as a parameter to TC search function

Post by *Stefan2 »

beb wrote: 2023-02-10, 10:32 UTC
'mshta "javascript" '

Cool :D

Thank you for sharing. :thumbsup:



 
Fla$her
Power Member
Power Member
Posts: 2299
Joined: 2020-01-18, 04:03 UTC

Re: Passing selected text from web or from clipboard as a parameter to TC search function

Post by *Fla$her »

2beb
It's a strange approach when WSH is used for one task, and a third-party utility is used for another, and for some reason it's all stuffed into bat, duplicating the creation of a variable. A triple hybrid instead of a full-fledged code. :shock:
Overquoting is evil! 👎
User avatar
beb
Senior Member
Senior Member
Posts: 434
Joined: 2009-09-20, 08:03 UTC
Location: Odesa, Ukraine

Re: Passing selected text from web or from clipboard as a parameter to TC search function

Post by *beb »

Stefan2 wrote: 2023-02-10, 12:05 UTC
beb wrote: 2023-02-10, 10:32 UTC 'mshta "javascript" '
Cool :D
Thank you for sharing. :thumbsup:
Here's a more compact version that utilizes powershell function:

Code: Select all

for /f "tokens=* delims=" %%i in ('powershell -command "Get-Clipboard"') do set "url=%%i"
echo %url%
Here's an example of how it could practically work, for instance with wget:
[Total Commander usercmd]:

Code: Select all

[em_wget_clip]
cmd=%commander_path%\Plugins\app\Downloads\wget_clip.cmd
[wget_clip.cmd]:

Code: Select all

@echo off
chcp 65001
REM runtime variables parsing
Setlocal EnableDelayedExpansion
REM path;cli;app
path %path%;%commander_path%\Plugins\app\Downloads
REM wget parameters (universal)
set params=-S -N --no-if-modified-since --no-hsts --user-agent="Mozilla"

REM downloads folder location
for /f "tokens=2,*" %%c in (
'reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v {374DE290-123F-4565-9164-39C4925E467B}'
) do set downloads=%%d

REM retrieving url from clipboard
for /f "tokens=* delims=" %%i in ('powershell -command "Get-Clipboard"') do set "url=%%i"

REM downloading...
@echo.&@echo downloading...&@echo.&@echo "%url%"&@echo.
wget !params! "%url%" -P "%downloads%"

REM checking output...
if ERRORLEVEL 1 (goto ERROR) else (goto OK)

:ERROR
:: wait 7 seconds then exit
@echo There's no URL in the clipboard
ping -n 8 ::1 >nul

:OK
exit/b
NB cmd code with checking option (starting from "REM checking output") in the specific example is redundant and can be omitted, it just shows a user can process errors if needed
#278521 User License
Total Commander [always the latest version, including betas] x86/x64 on Win10 x64/Android 10
Post Reply