Help launching Google Incognito search but with custom chrome path and search query Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ZythiQ
Posts: 12
Joined: 28 Jan 2021, 21:11

Help launching Google Incognito search but with custom chrome path and search query

Post by ZythiQ » 05 Dec 2021, 17:00

I can't seem to get this to work since my understanding of % is iffy at best:

Code: Select all

chromePath := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
run %chromePath% -incognito "http://www.google.com/search?q=%clipboard%"
This does work (searches whatever is in the clipboard with google chrome's incognito mode):

Code: Select all

run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" -incognito "http://www.google.com/search?q=%clipboard%"
It looks like I am not referencing chromePath correctly, but when I use what's below, it doesn't work:

Code: Select all

chromePath := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
run % chromePath "-incognito" "http://www.google.com/search?q=" + clipboard
I imagine that's because it is trying to combine "-incognito" but I'm not sure how to stop that from happening.

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

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by mikeyww » 05 Dec 2021, 17:12

Code: Select all

Run, chrome.exe -incognito http://www.google.com/search?q=%Clipboard%

ZythiQ
Posts: 12
Joined: 28 Jan 2021, 21:11

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by ZythiQ » 05 Dec 2021, 17:20

I got excited at first, but unfortunately, that doesn't work... AHK raises a "could not find file/application" error.

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by Xtra » 05 Dec 2021, 18:11

Code: Select all

chromePath := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
run % chromePath . " -incognito " . "http://www.google.com/search?q=" . clipboard
or:

Code: Select all

chromePath := "C:\Program Files (x86)\Google\Chrome\Application"
Run, chrome.exe -incognito http://www.google.com/search?q=%clipboard%, % chromePath
HTH

ZythiQ
Posts: 12
Joined: 28 Jan 2021, 21:11

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by ZythiQ » 05 Dec 2021, 18:53

That doesn't work either for the same reason. I think the closest I've gotten is with:

Code: Select all

chromePath := "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
run %chromePath% -incognito "http://www.google.com/search?q=%clipboard%"
Since chromePath is a string, I can't double reference it like %chromePath%; it spits out nothing. Is there a way to single reference it without the % at the beginning of the string? That is like:

Code: Select all

run chromePath -incognito "http://www.google.com/search?q=%clipboard%"
Because "- incognito" and "http://www.google.com/search?q=%clipboard%" are parameters of the program being run, at least I think...

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

Re: Help launching Google Incognito search but with custom chrome path and search query  Topic is solved

Post by mikeyww » 05 Dec 2021, 19:17

This worked for me.

Code: Select all

chromePath := ProgramFiles "\Google\Chrome\Application\chrome.exe"
Run, % chromePath " -incognito " fix("http://www.google.com/search?q=" Clipboard)

fix(url) {
 RegExMatch(url, "^(https?://)?(.+?)(/)?$", part)
 Loop, Parse, part2
  text .= A_LoopField ~= "[$&+,:;@""<>`%{}|\\^~[\] `]" ? Format("%{:X}", Asc(A_LoopField)) : A_LoopField
 Return part1 text part3
}

User avatar
Xtra
Posts: 2744
Joined: 02 Oct 2015, 12:15

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by Xtra » 05 Dec 2021, 21:29

ZythiQ wrote:
05 Dec 2021, 18:53
Is there a way to single reference it without the % at the beginning of the string? That is like:
Sure easy enough:
run %chromePath% -incognito "http://www.google.com/search?q=%clipboard%"

But the clipboard contents is your main issue see/try Mikeys post above. There are other escape url scripts on the forum they do the same thing.

ZythiQ
Posts: 12
Joined: 28 Jan 2021, 21:11

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by ZythiQ » 05 Dec 2021, 21:42

Thank you both for the help! I'll have to work out what that function does now.

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

Re: Help launching Google Incognito search but with custom chrome path and search query

Post by mikeyww » 05 Dec 2021, 21:44

It just converts the "special symbols" (punctuation-like) into hex values prefixed by %. This is mostly an issue when the search string contains spaces. A URL cannot contain a space, so it uses %20 instead.

Post Reply

Return to “Ask for Help (v1)”