search string in firefox.exe without http Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
mongtas
Posts: 18
Joined: 02 Jun 2020, 12:25

search string in firefox.exe without http

Post by mongtas » 28 Jan 2022, 12:01

hi guys,
i hope i am in right section.

i use a search string in the firefox adress bar like: "gul %searchword%"

now i tried to use clipboard with a ahk line to do that search. but it does always try to open a http site.

it opens: http://www.gul.com

Code: Select all

#o::
run, firefox.exe gul %clipboard%
return

but i want a raw input of "gul %clipboard%" into the firefox adress line, so it opens my custom search key result from firefox.

can anyone help ?
thanks in advance

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: search string in firefox.exe without http

Post by mikeyww » 28 Jan 2022, 13:10

Code: Select all

#o::Run, % "firefox.exe https://www.google.com/search?q=" encodeDecodeURI("gul" clipboard)

encodeDecodeURI(str, encode := true, component := true) {
 ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84825
 Static doc, js
 If !doc {
  doc := ComObjCreate("htmlfile"), doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
  js  := doc.parentWindow
  (doc.documentMode < 9 && js.execScript())
 }
 Return js[(encode ? "en" : "de") "codeURI" (component ? "Component" : "")](str)
}
An alternative is simply to send your string to the address bar after you activate Firefox.

Code: Select all

#o Up::
Run, firefox.exe
WinWaitActive, ahk_exe firefox.exe,, 5
Send % ErrorLevel ? "" : "gul" Clipboard "`n"
Return
You can adjust according to whether the program is already running, you need to create a new tab, etc.

mongtas
Posts: 18
Joined: 02 Jun 2020, 12:25

Re: search string in firefox.exe without http

Post by mongtas » 28 Jan 2022, 15:36

first of all thank you very much.

i tried the first method. then i got a google search result for "gul test". (test is the copied text)
mikeyww wrote:
28 Jan 2022, 13:10

Code: Select all

#o::Run, % "firefox.exe https://www.google.com/search?q=" encodeDecodeURI("gul" clipboard)

encodeDecodeURI(str, encode := true, component := true) {
 ; https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84825
 Static doc, js
 If !doc {
  doc := ComObjCreate("htmlfile"), doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
  js  := doc.parentWindow
  (doc.documentMode < 9 && js.execScript())
 }
 Return js[(encode ? "en" : "de") "codeURI" (component ? "Component" : "")](str)
}


then i tried it without the "https://www.google.com/search?q=" part. like:

Code: Select all

#o::Run, % "firefox.exe" encodeDecodeURI("gul " clipboard)

then firefox opens with the following adress line: "file:///C:/tools/Autohotkey%00/gul%20test"

could you help ?

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: search string in firefox.exe without http

Post by mikeyww » 28 Jan 2022, 18:58

Since you are searching for "gul %searchword%", it looks like script #1 worked as expected. You can try script #2 as well.

What is your example of what should actually happen?

mongtas
Posts: 18
Joined: 02 Jun 2020, 12:25

Re: search string in firefox.exe without http

Post by mongtas » 29 Jan 2022, 07:53

mikeyww wrote:
28 Jan 2022, 18:58
Since you are searching for "gul %searchword%", it looks like script #1 worked as expected. You can try script #2 as well.

What is your example of what should actually happen?
hi, it should not do a GOOGLE search.

it should just enter "gul %searchword%" into the adressline in firefox and serach. since "gul" is a specific searchkey i am using in firefox to search in a custom seach-engine (not google).

when i type "gul android" in my firefox i get the follwing result. because i am using a custom search.

Image


i also tried script#2 it also not worked. it also did a google search :crazy:

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: search string in firefox.exe without http  Topic is solved

Post by mikeyww » 29 Jan 2022, 08:37

To aid your testing, I have added a space after "gul", and deleted the final Enter here. That will enable you to confirm what is on the address bar.

Code: Select all

winTitle = ahk_exe firefox.exe
#o Up::
If running := WinExist(winTitle) {
 WinActivate
 Send ^t
} Else Run, firefox.exe
WinWaitActive, %winTitle%,, 5
If ErrorLevel
 Return
Sleep, 500 * !running
Send gul %Clipboard%
; Send `n
Return

mongtas
Posts: 18
Joined: 02 Jun 2020, 12:25

Re: search string in firefox.exe without http

Post by mongtas » 29 Jan 2022, 13:19

thank you so much. now it worked. but still wondering, why the first method not working. i would prefer first method, because i think its more relialible.

but still thank you very much for your help

User avatar
mikeyww
Posts: 26884
Joined: 09 Sep 2014, 18:38

Re: search string in firefox.exe without http

Post by mikeyww » 29 Jan 2022, 13:22

I believe that this would relate to how and when Firefox translates the abbreviations for the search engines. If you have a specific search engine, you can simply put the url in place of where you had "gul" in your original script.

Post Reply

Return to “Ask for Help (v1)”