Need help with Run, %clipboard% command

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
ronb08
Posts: 2
Joined: 06 May 2017, 06:27

Need help with Run, %clipboard% command

06 May 2017, 08:05

Hi guys,
I'm trying to setup a script which pastes all the text content of my clipboard to a custom site like amazon (&wiki) and do a search.
problem is that it only paste's the 1st word of the string from the clipboard and puts every other word in the address line in a new tab.
it only does this with the "chrome.exe" in front

!s::
Send, ^c
Sleep 200
Run, chrome.exe https://www.amazon.com/s/ref=nb_sb_noss ... %ClipBoard%
return

!w::
Send, ^c
Sleep 200
Run, chrome.exe https://en.wikipedia.org/wiki/%ClipBoard%
return

If you remove the "chrome.exe" it works fine and takes the whole string from %clipboard%
however I don't want to do that because I don't want it to open my default browser and don't want to change it.

Anybody knows what goes wrong here?
thanks a million, i can't seem to figure out how to fix being a newbie to this stuff :crazy:
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Need help with Run, %clipboard% command

06 May 2017, 09:26

Web addresses don't support spaces in them, so when you are copying more than one word, the space is seen as a new tab. You would have to StringReplace the space with either a _ and if a Wiki page exists for those words, it will load it.
Example:
https://en.wikipedia.org/wiki/Panel_painting
Crashm87
Posts: 48
Joined: 25 Jul 2016, 13:12

Re: Need help with Run, %clipboard% command

06 May 2017, 09:33

Here is example code

Code: Select all

!w::
Send, ^c
Sleep 200
wiki := "https://en.wikipedia.org/wiki/"
clip = %Clipboard%
StringReplace, clip, clip, %A_Space%,_, All
;MsgBox %wiki%%clip%   ;debug
Run, chrome.exe %wiki%%Clip%
return
With this, you should be able to apply the same thing to your Amazon searches
garry
Posts: 3787
Joined: 22 Dec 2013, 12:50

Re: Need help with Run, %clipboard% command

06 May 2017, 11:49

.... and wikipedia want stringupper in names ...

Code: Select all

transform,s,chr,32
c1="alex van warmerdam"
StringReplace,c1,c1,`",, All
Loop,parse,c1,%s%
  {
  x:=a_loopfield
  if x in da,do,de,van
    {
    e .= x . "_"
    continue
    }
  StringUpper,x,x,T
  e .= x . "_"
  }
stringtrimright,c1,e,1
run, https://en.wikipedia.org/wiki/%c1%
return
ronb08
Posts: 2
Joined: 06 May 2017, 06:27

Re: Need help with Run, %clipboard% command

06 May 2017, 14:39

Thanks Crashm87 I have tested your code and it works however it puts -as you said- the _ in between the kw's which influences the amazon algorithm. It does not show ads which is what I need for research purposes.

Please note that when removing the chrome.exe it works:

Code: Select all

!a::
Send, ^c
Sleep 200
Run, https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias`%3Daps&field-keywords=%ClipBoard%
return

!w::
Send, ^c
Sleep 200
Run, https://en.wikipedia.org/wiki/%ClipBoard%
return
User avatar
noname
Posts: 516
Joined: 19 Nov 2013, 09:15

Re: Need help with Run, %clipboard% command

07 May 2017, 01:24

Code: Select all

!a::
Send, ^c
Sleep 200
enc_Clipboard:=UriEncode(clipboard)
Run, chrome.exe https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias`%3Daps&field-keywords=%enc_Clipboard%
return



UriEncode(Uri) {
		VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
		StrPut(Uri, &Var, "UTF-8")
		f := A_FormatInteger
		SetFormat, IntegerFast, H
		while Code := NumGet(Var, A_Index - 1, "UChar")
			if (Code >= 0x30 && Code <= 0x39 ; 0-9
			|| Code >= 0x41 && Code <= 0x5A ; A-Z
			|| Code >= 0x61 && Code <= 0x7A) ; a-z
				Res .= Chr(Code)
		else
			Res .= "%" . SubStr(Code + 0x100, -1)
		SetFormat, IntegerFast, %f%
		return, Res
}
Guest

Re: Need help with Run, %clipboard% command

07 May 2017, 06:49

noname wrote:

Code: Select all

!a::
Send, ^c
Sleep 200
enc_Clipboard:=UriEncode(clipboard)
Run, chrome.exe https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias`%3Daps&field-keywords=%enc_Clipboard%
return



UriEncode(Uri) {
		VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
		StrPut(Uri, &Var, "UTF-8")
		f := A_FormatInteger
		SetFormat, IntegerFast, H
		while Code := NumGet(Var, A_Index - 1, "UChar")
			if (Code >= 0x30 && Code <= 0x39 ; 0-9
			|| Code >= 0x41 && Code <= 0x5A ; A-Z
			|| Code >= 0x61 && Code <= 0x7A) ; a-z
				Res .= Chr(Code)
		else
			Res .= "%" . SubStr(Code + 0x100, -1)
		SetFormat, IntegerFast, %f%
		return, Res
}
wow thats alot of code, it works perfectly thanks so much. Can you tell some more how you got this code, did you write it or got it from somewhere else? I would NEVER be able to pull off that kind of code lol

I tried to merge it into wiki too this doesn't seem to match,

I just did this after I tested your code working on amazon:

Code: Select all

!a::
Send, ^c
Sleep 200
enc_Clipboard:=UriEncode(clipboard)
Run, chrome.exe https://www.amazon.com/s/ref=nb_sb_noss_2?url=search-alias`%3Daps&field-keywords=%enc_Clipboard%
return

!w::
Send, ^c
Sleep 200
enc_Clipboard:=UriEncode(clipboard)
Run, chrome.exe https://en.wikipedia.org/wiki/%enc_ClipBoard%
return

UriEncode(Uri) {
		VarSetCapacity(Var, StrPut(Uri, "UTF-8"), 0)
		StrPut(Uri, &Var, "UTF-8")
		f := A_FormatInteger
		SetFormat, IntegerFast, H
		while Code := NumGet(Var, A_Index - 1, "UChar")
			if (Code >= 0x30 && Code <= 0x39 ; 0-9
			|| Code >= 0x41 && Code <= 0x5A ; A-Z
			|| Code >= 0x61 && Code <= 0x7A) ; a-z
				Res .= Chr(Code)
		else
			Res .= "%" . SubStr(Code + 0x100, -1)
		SetFormat, IntegerFast, %f%
		return, Res
}
can you tell how to make this work on any other site?
User avatar
noname
Posts: 516
Joined: 19 Nov 2013, 09:15

Re: Need help with Run, %clipboard% command

07 May 2017, 08:47

UriEncode is as old as the "web" UNIVERSE ;) there must be dozens of versions on the forum.

Just google : uriencode site:https://autohotkey.com

Here is one : https://autohotkey.com/board/topic/7539 ... -function/

The wiki works for me maybe you used a exceptional character in your search item?


It is a nice way of using Wikipedia thanks I will keep the shortcut !!
Guest

Re: Need help with Run, %clipboard% command

08 May 2017, 10:35

yes it now seems to work on mine as well, my system apparenly needed a reboot hehe.
Thanks for the links, you mean with that that you didnt write that code yourself?
Thanks for the help in any case!
User avatar
noname
Posts: 516
Joined: 19 Nov 2013, 09:15

Re: Need help with Run, %clipboard% command

08 May 2017, 12:20

No i did not write the code , i keep note of functions i see in scripts/functions forum if they are looking interesting.This one has been modified a lot so i do not know the original post.
If you look closely you see it is rather simple ,if a character is a-z or A-Z or 0-9 keep it , otherwise use the hex value with prefix % so space is 0x20 hex convert it to %20.

Ha the good old reset button did it again.........

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot] and 75 guests