HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

If you are experiencing problems with "Everything", post here for assistance.
Post Reply
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

Below are instructions to create and run a script to autoload a predefined set (time-ordered in this case) of search expressions each in its own window/process. (btw this forum page would not let me attach a .txt file, oddly, it kept insisting any attachment be an "extension.")

I got it mostly working, but there are a few issues I would like some input on:

1. MINIMIZE: How do I modify the line Start-process .\everything.exe -Argumentlist "$search" to automatically MINIMIZE the new window after it is created? (OR modify the line in the script that creates the argument $search to do so)?

2. SEARCH TYPE: How do I specify in the line Start-process the TYPE of search to perform, so that it includes command to search a specific type, Video, Picture, etc. (OR modify the line in the script that create the argument $search to do so)?

3. Can sleep of 500 milliseconds be shortened?

4. I tested it withn a VERY long list, 800 lines in search.txt. HOWEVER: it quit at 645, not sure if that was an Everything limit, system memory limit (not likely, system had plenty left), or something I accidentally did. Ideas?

5. In the resulting windows, some things did not work. Right-click on any of the results FAILED to show context menu (like "Open Path", etc.). Perhaps this was related to the early termination as described in 4?

6. Is there a way to provide the following more simpy just as an ARGUMENT to Start-Process, or by hand in a command or powershell window:
- file with list of search expressions, separated by <CR> (in windows)
- type of search to perform on all
- auto-minimize resulting window.

The goal is to keep it simple, input being just a list of search expressions, one per line, in a text file, which is easily extracted from "Search History.csv" using EXCELL as described, and can be sorted, edited at will.

THANK YOU!

HERE ARE THE INSTRUCTIONS I PUT TOGETHER, INCLUDING THE SCRIPT:

find most recent Search History.csv, probably in C:\Users\<your account name>\AppData\Roaming\Everything

Open Search History.csv in Excell

Sort based on date
(HOME tab, Sort&FIler on rt., Custom Sort, select "Last Search Date" in leftmost menu, OK)

NOTE: most recent at bottom

Select desired rows
(Click bottom cell on left or the newest one you want to restore, scroll up to find oldest you want to restore, Shift/click oldest)

Copy to clipboard
(Rt. click highlit cells, "Copy")

Paste to Notepad

Save as searches.txt to location where Everything.exe you are using resides, probably C:\Program Files\Everything)

Open a new Notepad, paste below into it and & save as Load_searches.txt.ps1 to folder where Everything.exe resides
Get-Content .\searches.txt | ForEach-Object {
$search = (-join ("-newwindow -search " , "`"" , $_ ) )
Start-Sleep -m 500
Start-process .\everything.exe -Argumentlist "$search"
}

start powershell in admin mode
(Start menu, search for Powershell, rt click, Run as Admin)

In powershell window, type:
Set-ExecutionPolicy Unrestricted

type:
cd "C:\Program Files\Everything" (including quotes, or location your Everything.exe resides)

type:
.\Load_searches.txt.ps1

Wait as Everything opens a new Search window containing all the search expressions in search.txt

For safety:
Set-ExecutionPolicy Restricted

In the future just repeat steps to extract a set a search expressions in txt form, save to overwrite searches.txt & repeat execution steps.
Last edited by stevenroussos on Thu Feb 14, 2019 6:37 pm, edited 1 time in total.
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

OK I just answered 1. with a little research. From https://stackify.com/what-is-powershell/ ("What is PowerShell Start Process? How to Execute a File from a Command Line in Windows")

Last line of script should be:
Start-process .\everything.exe -Argumentlist "$search" -WindowStyle Minimized

Still would appreciate help on the other items
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

I tried this to simply add a space and "type:Video" , as well as 10 other varitaions on the syntax. Nothing I do works.

The below creates the search windows minimized, but just smashes "type:Video" up against the line from the file so searches for the wrong string.

For instance, if the line from the file is "CATVIIDEO" the search expression used is CATVIDEOtype:Video

Get-Content .\searches.txt | ForEach-Object {
$line = $_
$space = "`""
$type = "type:Video"
$search = (-join ("-newwindow -search " , $space , $line))
$searchWtype = (-join ($search , $space , $type))
Start-Sleep -m 500
Start-process .\everything.exe -Argumentlist "$searchWtype" -WindowStyle Minimized
}
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by NotNull »

A basic PowerShell version to give you some inspiration:

Code: Select all

Import-CSV "$env:appdata\Everything\Search History.csv" | Out-GridView -Title "Select the history queris to open in separate Everything windows" -PassThru | % { start-process -WindowStyle Minimized -FilePath 'C:\Tools\Everything\Everything.exe'  -ArgumentList '-newwindow','-search',$_.Search }
(That's one line)

When you run this command, a spreadsheet like presentation of the Search History opens.
Sort entries by clicking the header
Select the queries you want to execute and press Enter (or click the OK button).

Notes:
- Change the paths to match your situation
- You will probably have to change Import-CSV "$env:appdata\Everything\Search History.csv" with (Import-CSV "$env:appdata\Everything\Search History.csv") to prevent the CSV to be locked (=opened).
- For a somewhat similar CMD version see viewtopic.php?f=2&t=6786
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

Oh that's cool, thanks!

That does eliminate the messing around with the .csv file in Excell, copying list to to new txt file etc., so GREAT!

HOWEVER I still cannot get it to proper add " type:Video" to the result. Seems like my code in my last message above should work, but it insists on NOT putting a space in and jamming "type"Video" right up against the search expression which of course mucks it all up.

Any suggestions (either for my method or your?)

THANK YOU!!!!!
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by NotNull »

stevenroussos wrote: Thu Feb 14, 2019 8:27 pm HOWEVER I still cannot get it to proper add " type:Video" to the result. Seems like my code in my last message above should work, but it insists on NOT putting a space in and jamming "type"Video" right up against the search expression which of course mucks it all up.
The type: function works different: it works on the Type column in Explorer or Everything, so you can search for type:"File folder" or type:"PDF file".
There is a filter Video and if you look at it's properties (Menu:Search > Organize filters ), you'll see macro = video.

That means that you can add video: to your search query (and remove the type:video) to limit the results to video files .
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

I still had the issue I desccribed:every attempt I made to add anything after the search expression with a space inbetween didn't work, no space, so I guess I am going to get "video:" just stuck up against the search expression from the input file a I did with "type:Video".

That's where I need help, forming the final $search variable (or in my case $searchWtype) properly with a space after the search string separating it from "type":video:" (now to be just "video:")

I'll play around a little more, but input on the latter question appreciated. I am very newbie to shell programming.

Thanks.
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by NotNull »

That -ArgumentList is very unintuitive. Still have to discover how it should be used properly (documentation is scarce).
It is *very* allergic to spaces and with a lot of """" things will work, but in this case I found another (simpler?) solution:

Code: Select all

Import-CSV "$env:appdata\Everything\Search History.csv" | Out-GridView -Title "Select the history queries to open in separate Everything windows" -PassThru | % { start-process -WindowStyle Minimized -FilePath 'C:\Tools\Everything\Everything.exe'  -ArgumentList '-newwindow','-search "video:',$_.Search,'"' }
(I hope I didn't make a typo :))

Let us know if this works for you ..
stevenroussos wrote: Thu Feb 14, 2019 10:06 pm I am very newbie to shell programming.
Respect for what you accomplished thus far!
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by NotNull »

OK, *finally* unraveled the secret to -Argumentlist. As always: pretty simple in hindsight ...


First of all. the -search options have to be in quotes (otherwise the entry after a space is seen as an Everything filelist:
-search "video: $search"

And because -Argumentlist already has to be in "", the 'inside "" around the -search options have to be escaped. In Powershell that is like this: `"
Giving you: -ArgumentList "-newwindow -search `"video: $search`""


Complete command (finally! :)):

Code: Select all

Import-CSV "$env:appdata\Everything\Search History.csv" | Out-GridView -Title "Select the history queries to open in separate Everything windows" -PassThru | % { start-process -WindowStyle Minimized -FilePath 'C:\Tools\Everything\Everything.exe'  -ArgumentList  "-newwindow -search `"video: $search`"" }

Thanks for asking this! Now I finally figured out -Argumentlist (next challenge: remembering it ...)
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

THANKS! The script worked!

However, that grid display to pick from leaves a few things to be desired.

- I would like it to put the "video"" AFTER the text of search expression, so that when I view all open Everything processes in Windows Task Manager, the start of the expression shows up first on the left.

- The date display is in that weird (forgot what it is called) mode of #seconds since some time in the 1600. I would be great to have it in std mm/dd/yyy

- There is no way to search for a certain text string and just have the cursor go there in the full list There is a search but then it only shows that single item. If you select it and then exit search mode it reverts to fiull list, positioned wherever it was when you started the search, so there is no way to select a row with the desired term, and SHFT-Select all rows from there back up to the top of the time-sorted list to open.

Got any tricks up your sleve to accomplish those things?
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by NotNull »

stevenroussos wrote: Mon Feb 18, 2019 6:46 pm THANKS! The script worked!

However, that grid display to pick from leaves a few things to be desired.
As said: "A basic PowerShell version to give you some inspiration" (cover the basics frist then finetuning)
I will take a look at it tomorrow evening (European timezone), but for indication:
I would like it to put the "video"" AFTER the text of search expression, so that when I view all open Everything processes in Windows Task Manager, the start of the expression shows up first on the left.
Doable.
- The date display is in that weird (forgot what it is called) mode of #seconds since some time in the 1600. I would be great to have it in std mm/dd/yyy
Doable. What date/time format do you prefer? 02/18/2019 22:10 ? 2019-02-18 22:10 ? Somnething else?
- There is no way to search for a certain text string and just have the cursor go there in the full list There is a search but then it only shows that single item. If you select it and then exit search mode it reverts to fiull list, positioned wherever it was when you started the search, so there is no way to select a row with the desired term, and SHFT-Select all rows from there back up to the top of the time-sorted list to open.
Doubt if this is doable, but will take a quick look.
Got any tricks up your sleeve to accomplish those things?
Maybe ..
stevenroussos
Posts: 40
Joined: Wed Apr 08, 2015 10:00 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by stevenroussos »

For the "doubtful" item, can it just start Excell and then grab the first selection to the system clipboard from there as its input? I could use Excell to view, sort search & then finally select & COPY the row texts.
NotNull
Posts: 5167
Joined: Wed May 24, 2017 9:22 pm

Re: HELP WITH: Instructions for Script to autoload a predefined set of search expressions each in its own window/process

Post by NotNull »

Oops, forgot about this one .. :?
Give me a couple of minutes.

EDIT: Got it working, except for quoting :( My original analysis turns out to be wrong (again!). Back to the drawing board ..
Post Reply