help with a search script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Geronimo
Posts: 11
Joined: 19 Oct 2019, 15:28

help with a search script

21 Sep 2021, 14:40

Hello,

I have an ahk script which is performing a search on multiple websites in the same time. So, when i press the Search button, the script opens all the webpages on which the search is performed, in tabs in the current opened window (or opening a new one if none is open) of the default browser.

My question is, how can i make it to open a new window for each search, despite if there are already opened windows...so what i don't want is that by making several subsequent searches to not append tabs on only one window and to open a new one each time Search button is pressed.

Hopefully someone will understand what i wrote and will help me out :))
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: help with a search script

21 Sep 2021, 18:26

Short of seeing your script, if there is no browser command line that fits, you could run a new instance of the browser, and then send the URL to it.

viewtopic.php?p=421379#p421379
Geronimo
Posts: 11
Joined: 19 Oct 2019, 15:28

Re: help with a search script

22 Sep 2021, 01:09

Here is my script:

maybe you can help me out with the lines i have to insert :)

thank you very much!


Code: Select all

SplitPath,a_scriptname, name, dir, ext, name_no_ext, drive
F1=%a_scriptdir%\%name_no_ext%.ini

I=15               ;- total checkboxes

Gui,2: Color, ControlColor, Black
Gui,2: Font, CDefault, Lucida Console

Loop,%i%
  {
  IniRead, Ch%A_Index%, %f1%, ss, Cb%A_Index% , 0
    If (Ch%A_Index% = 1)
      Cb%A_Index% = Checked
    Else
      Cb%A_Index% =
  }

Gui,2: Show, x100 y5 w300 h600, ;%name_no_ext%

Gui,2: Add, Edit,     x20 y5 w265 h20 cWhite vSearch,%src%

Gui,2: Add, CheckBox, x20 y295 vCh10 %cb10% cYellow, Delcampe

; Gui,2: Add, CheckBox, x20 y385 vCh97 cb
; Gui,2: Add, CheckBox, x20 y405 vCh98 gCheckAll cYellow, Select All

Gui,2: Add, CheckBox, x20 y495 vCh99 vBCB gToggle cYellow, Straine
Gui,2: Add, Button, x10 y515 w100 h26 gAA ,Start
; Gui,2: Add, Button, x150 y420 w100 h26 gAA ,Clear
GuiControl,2:Focus,search
return


Toggle:
	Gui,2:Submit,NoHide
	if(A_GuiControl="TCB")
		Loop 9	
			GuiControl,2:,Button%A_Index%,% TCB
	else	
		Loop 6	
			GuiControl,2:,% "Button" A_Index+9,% BCB
	return

; CheckAll:
;Loop, %i%
;    GuiControl,2:, Ch%A_Index%, 1
; GuiControl,2:, Ch99, 0
; Return

; UnCheckAll:
; Loop, %i%
;    GuiControl,2:, Ch%A_Index%, 0
; GuiControl,2:, Ch98, 0
; Return

AA:
Gui,2: submit, nohide
search_spatiu=%search%

StringReplace,Search, Search, %A_space%, +, All

search=%search%
{
    StringReplace,search_plus,search,%A_space%, +, All
}

FormatTime, time, A_Now, dd.MM.yyyy H:mm
FileAppend, %time% | %search_spatiu% `n, history.txt


  if Ch10
    run,https://www.delcampe.net/en_US/collectibles/search?term=%search_plus%&excluded_terms=&country=NET&is_searchable_in_translations=0&is_searchable_in_descriptions=0&search_mode=all&show_type=all&display_ongoing=ongoing&started_days=&ended_hours=&all-payment-methods=on&min_price=&max_price=&order=price_desc&seller_localisation=world&blacklisted_sellers_included=0
  
  
return

time:

2GuiClose:
Gui,2: Submit
Loop,%i%
  {
  e= % ch%a_index%
  IniWrite, %e%, %f1%, ss, Cb%a_index%
  }
ExitApp
;===========================================================================
[Mod edit: [code][/code] tags added.]
Last edited by Geronimo on 24 Sep 2021, 12:04, edited 2 times in total.
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: help with a search script

22 Sep 2021, 06:08

Example:

Code: Select all

Run, chrome.exe --new-window https://www.okazii.ro/cautare/test.html?sort=pret_desc
Geronimo
Posts: 11
Joined: 19 Oct 2019, 15:28

Re: help with a search script

22 Sep 2021, 12:15

Thank you very much!

But this i think, will open each site i want to search in a new window...now there are only 2 but there will be around 9 -10 websites to be searched at once.

what i am trying to do, is when i am performing a new search to open a new browser window with 9-10 tabs one for each website...
is this possible?
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: help with a search script

22 Sep 2021, 14:59

Your posted question was, "My question is, how can i make it to open a new window for each search". If that is actually not your question, but you want tabs instead, you can omit the "--new-window" in the command. The "--new-window" can be used initially if you want a new window.
Geronimo
Posts: 11
Joined: 19 Oct 2019, 15:28

Re: help with a search script

22 Sep 2021, 15:07

Yes, you are perfectly right
I was almost convinced that I had not expressed myself properly from the beginning
When I say search, I mean the search for a certain word
For example the word "home" - after entering the word in the search field, I press the SEARCH button.
Then the script opens 9-10 tabs in the current default browser window. Each tab loads a search engine in which the search field is pre-filled with the word I searched for, in our case "house"
What I want is that every time I search for another word and press the SEARCH button, the script will open a new window with 9 tabs. So practically a new window will open for each word I searched for or every time I press the SEARCH button.
So a new window for "home", "car", "dog" ... or whatever i am searching for, with tabs for each website used in the script...
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: help with a search script

22 Sep 2021, 15:13

Here is a general approach. You can add more URLs to the function (new Run lines with a URL on each).

Code: Select all

find("test")
find("car")

find(term) { ; Open a new browser window; run multiple searches
 WinMinimize, % wTitle := "ahk_exe chrome.exe"
 Run, chrome.exe --new-window https://www.google.com/search?q=%term%
 WinWaitActive, %wTitle%
 Run, chrome.exe http://www.autohotkey.com/
}
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: help with a search script

22 Sep 2021, 15:25

or short ... in your example above with checkboxes , after label AA:

Code: Select all

AA:
Gui,2: submit, nohide
Run, chrome.exe --new-window
sleep,5000
;... continua aici
User avatar
mikeyww
Posts: 26599
Joined: 09 Sep 2014, 18:38

Re: help with a search script

22 Sep 2021, 15:29

Good one-- that might be easier in terms of the flow.
Geronimo
Posts: 11
Joined: 19 Oct 2019, 15:28

Re: help with a search script

23 Sep 2021, 01:46

Ok, i added all the websites i want to use for search at once (with checkboxex) to have a complete ideea of what the script is doing.

I also added the few lines @garry mentioned, but this only opens a new chrome window, than waits a bit and after that all the websites will open in tabs but in the default browser (firefox in my case) and not in the previously opened chrome window.

So i just added on each run line firefox.exe before the url as shown below
Also it seems that WinWaitActive was necessary...this way it opens all 15 websites in 15 tabs in the same window, otherwise, without winwaitactive it opened only 4-5 of then in the same window, and the rest in another window.

So, i don't know if this is the best solution, but it seems it's working :))

So i want to thank all of you for the input and for your time on this matter!

All the best!

Code: Select all


  if Ch10
    run, firefox.exe https://www.delcampe.net/en_US/collectibles/search?term=%search_plus%&excluded_terms=&country=NET&is_searchable_in_translations=0&is_searchable_in_descriptions=0&search_mode=all&show_type=all&display_ongoing=ongoing&started_days=&ended_hours=&all-payment-methods=on&min_price=&max_price=&order=price_desc&seller_localisation=world&blacklisted_sellers_included=0
  if Ch11
    run, firefox.exe https://www.livre-rare-book.com/search/results?hasImage=false&resultsPerPage=100&q=%search_plus%&sorting=PRICE_DESCENDING&l=en&ageFilter=ALL
  if Ch12
    run, firefox.exe https://www.ebay.com/sch/i.html?_from=R40&_nkw=%search_plus%&_sacat=0&_sop=16&_stpos=11377&_fcid=1
  if Ch13
    run, firefox.exe https://www.abebooks.com/servlet/SearchResults?cm_sp=sort-_-SRP-_-Results&kn=%search_abe%&sortby=1
  if Ch14
    run, firefox.exe https://fr.shopping.rakuten.com/s/%search_plus%?s=2
  if Ch15
    run, firefox.exe https://www.kijiji.it/%search_plus%/?sort=price-desc
Last edited by Geronimo on 24 Sep 2021, 12:05, edited 1 time in total.
garry
Posts: 3740
Joined: 22 Dec 2013, 12:50

Re: help with a search script

23 Sep 2021, 07:52

I think the first run should be after label 'AA:'
run, firefox.exe --new-window
after then you can run the checked 'url' , if your default browser is firefox, not needed to add the browser name ( run, %url% )

I have a problem with winwaitactive when first run the browser ( run, firefox.exe --new-window )
winwaitactive is ok when Firefox appears but should wait until the page is fully loaded ( at least add a sleep command )
maybe also use runwait .... (?)

( if want , you can contact a romanian autohotkey-user called 'robodesign' )

Code: Select all

searchx="Maria Tanase"
    stringreplace,searchx,searchx,`",`%22,all
    stringreplace,searchx,searchx,%a_space%,`%20,all
;----
browser:="firefox.exe "  ;  ( chrome is my default browser )
Runwait, %browser%--new-window
sc:="ahk_exe firefox.exe"
hd:="Mozilla Firefox"
WinWait,%hd%,,9   ;- wait maximal 9 seconds / otherwise if OK immediatelly continue
if ErrorLevel
 {
 MsgBox, 262208, , WinWait timed out.`nNOT FOUND the title 'Mozilla Firefox'
 Exitapp
 }
IfWinNotActive ,%sc%,,WinActivate,%sc%
  WinWaitActive,%sc%
msgbox, 262208, ,OK...but not fully loaded`nWait until webpage is fully loaded
sleep,2000  ;- at least you can add a sleep command
;- pictures
runwait,%browser%https://www.bing.com/images/search?q=%searchx%&FORM=HDRSC2
;- pictures
runwait,%browser%https://www.flickr.com/search/?q=%searchx%
;- pictures
runwait,%browser%https://www.google.com/search?q=%searchx%&tbm=isch
exitapp
Example-2 / run chrome fullscreen

Code: Select all

;-------- run in chrome browser ------------------
searchx="Maria Tanase"
    stringreplace,searchx,searchx,`",`%22,all
    stringreplace,searchx,searchx,%a_space%,`%20,all
;----
settitlematchmode,2
browser:="chrome.exe "
;browser:="C:\Program Files\Google\Chrome\Application\chrome.exe "
;Runwait, %browser%--start-fullscreen --new-window   ;- no success
Runwait, %browser% --new-window
sc:="ahk_exe chrome.exe"
hd:="Google Chrome"
WinWait,%hd%,,9   ;- wait maximal 9 seconds / otherwise if OK immediatelly continue
if ErrorLevel
 {
 MsgBox, 262208, , WinWait timed out.`nNOT FOUND the title 'chrome'
 Exitapp
 }
IfWinNotActive ,%sc%,,WinActivate,%sc%
  WinWaitActive,%sc%
;msgbox, 262208, ,OK...but maybe not fully loaded`nWait until webpage is fully loaded
sleep,500
;--------- run chrome fullscreen -------------------------
;- https://www.autohotkey.com/boards/viewtopic.php?t=67580    user boiler
WinGet, WinStatus, MinMax, ahk_exe chrome.exe
if (WinStatus != 0)
	WinRestore, ahk_exe chrome.exe
WA:=A_screenwidth,HA:=A_screenheight,xx:=100
WinGetPos,,,, TaskBarHeight, ahk_class Shell_TrayWnd
hx:=HA-TaskBarHeight
w:=(wa*100)/xx,h:=hx 
WinMove, ahk_exe chrome.exe,,0,0,%w%,%hx%
;----------
sleep,3000
;- pictures
runwait,%browser%https://www.bing.com/images/search?q=%searchx%&FORM=HDRSC2
;- pictures
runwait,%browser%https://www.flickr.com/search/?q=%searchx%
;- pictures
runwait,%browser%https://www.google.com/search?q=%searchx%&tbm=isch
exitapp
;=======================================================
Geronimo
Posts: 11
Joined: 19 Oct 2019, 15:28

Re: help with a search script

25 Sep 2021, 02:41

Dear @garry ,

Thank you very much for all your time and effort. I will implement the changes you suggested and hopefully it will work smooth :)

Thanks again,

all the best!!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 152 guests