StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 Search Google for Selected Text
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Rob

USA
2573 Posts

Posted - 03/09/2012 :  07:15:40  Show Profile  Visit Rob's Homepage  Reply with Quote
From forum member Kingron comes an action which searches Google for the selected text. So, if you highlight a segment of text, this action will copy it to the clipboard then open up a browser and perform a Google search for the selected text:

acSendKeys("{DELAY=50}^c")
acDelay(50)
local s = acGetClipboardText()
s = 'https://www.google.com/search?hl=en&newwindow=1&output=search&q=' .. s
acShellExecute("open","rundll32.exe", "url.dll,FileProtocolHandler "..s, nil, 1)

Hax

128 Posts

Posted - 03/09/2012 :  08:47:45  Show Profile  Reply with Quote
If you want to change the language version of Google Search, simply replace "en" with a different country code top-level domain. For instance, "es" for Spanish, "de" for German, "pl" for Polish and so on.
Go to Top of Page

breakcore

Russia
74 Posts

Posted - 03/11/2012 :  16:06:43  Show Profile  Reply with Quote
quote:
searches Google for the selected text

I guess it searches opening a default brouser. What if i want to run chrome logged in to a certain profile?
Normally in SI I did that making an Autoit script which was launched by assigned gesture. But in S+ I can't figure out what the correct syntax is for launching program with parameters.

here:
acRunProgram("G:\\Program Files\\AutoIt3\\AutoIt3.exe", "G:\other\scripts\AutoIt\search.au3","",0)
i got this error:
:14:invalid escape sequence near '\0'

ps: here is one string from my autoit script:
ShellExecute("C:\Users\"&@UserName&"\AppData\Local\Google\Chrome\Application\chrome.exe","--login-user=***@gmail.com --login-password=*** "&"http://www.google.ca/search?hl=en&q=" & $SearchQuery)
Do lua script have an alternative for that?

Edited by - breakcore on 03/11/2012 16:07:26
Go to Top of Page

Rob

USA
2573 Posts

Posted - 03/11/2012 :  16:33:41  Show Profile  Visit Rob's Homepage  Reply with Quote
Typing from my phone, so I can't give a thorough example for replicating your autoit script, but all strings in lua must have special characters escaped. your g:\other\... should be g:\\other\\...
Go to Top of Page

breakcore

Russia
74 Posts

Posted - 03/12/2012 :  05:35:36  Show Profile  Reply with Quote
quote:
Originally posted by Rob

Typing from my phone, so I can't give a thorough example for replicating your autoit script, but all strings in lua must have special characters escaped. your g:\other\... should be g:\\other\\...


Thanks! it's working now.
plus the parameter with spaces in it passes correctly only if enclosed additionally with single quotes:
acRunProgram("C:\\app.exe",'"parameter with spaces"',"",0)
otherwise only the part before the first space is passing. i think this shoul'd be described in the action info.
Go to Top of Page

Hax

128 Posts

Posted - 05/05/2012 :  08:44:18  Show Profile  Reply with Quote
It doesn't work properly with the ampersand character. For instance, the selected text like "Tom & Jerry" is always getting cut after "Tom". Is there any workaround for this?
Go to Top of Page

Rob

USA
2573 Posts

Posted - 05/05/2012 :  19:14:42  Show Profile  Visit Rob's Homepage  Reply with Quote
That's because the search string must be URL encoded or the server thinks you're delimiting a query string parameter.

Check these links for more info (I'm pressed for time at the moment and can't put a script together for you):

http://stackoverflow.com/questions/4297655/lua-string-replace

http://www.lua.org/pil/20.1.html (search for "replace")

You want to replace all "&" with "%26" and for good measure, replace " " with "%20" (in your search string only ["Tom & Jerry" should look like "Tom%20%26%20Jerry" in the URL itself).

Again, I haven't tested anything, but that's the root of the issue.
Go to Top of Page

Hax

128 Posts

Posted - 05/06/2012 :  04:51:24  Show Profile  Reply with Quote
Thanks for the hint.

I've just combined a S+ gesture with some compiled AHK script (once again!) and now it works like a charm with all those special characters.
Go to Top of Page

Marcel

New Zealand
4 Posts

Posted - 04/11/2013 :  19:18:51  Show Profile  Reply with Quote
Is it possible to detect if text is selected, ready to be copied? I'm just trying to integrate this function with the default "Open Link in New Tab / Open New Tab" action so that if text is selected, a Google search in a new tab will be done.
Go to Top of Page

Marcel

New Zealand
4 Posts

Posted - 04/11/2013 :  19:37:56  Show Profile  Reply with Quote
Actually, the following works how I want it to, it just makes a sound if there is a no text selected (as it would if text isn't selected and Ctrl+c is pressed) which is just a little annoying. I tweaked the default "Open Link in New Tab / Open New Tab" action.

-- this code does one of three things:
--
--  - if the mouse cursor is a HAND, the link below the cursor
--    is opened in a new tab.
--  - If the mouse cursor is not a HAND and text is not selected
--    a new browser tab is opened.
--  - If text is selected, a Google search is opened in a new tab
--    using the selected text as the search query.
--
-- this action is executed by holding the stroke button and
-- clicking the left mouse button, either over a link or anywhere
-- over the browser for a new tab, with text selected if a Google
-- search is desired.

if acGetMouseCursorType() == "HAND" then
	acMouseClick(gsx, gsy, 1, 1, 1) 	
else
	local sb = acGetClipboardText()
	acSendKeys("{DELAY=50}^c")
	acDelay(50)
	local sa = acGetClipboardText()
	if sa ~= sb then
		sa = 'https://www.google.co.nz/search?q='..sa
		acShellExecute("open","rundll32.exe", 
			"url.dll,FileProtocolHandler "..sa, nil, 1)
	else
		acSendKeys("^t")
	end
end

Go to Top of Page

Alex22

Ukraine
19 Posts

Posted - 10/05/2015 :  12:01:23  Show Profile  Reply with Quote
I modify Rob`s script for non-default portable browser.
acSendKeys("{DELAY=50}^c")
acDelay(50)
local s = acGetClipboardText()
s = 'http://yandex.ua/yandsearch?rdrnd=312365&text='..s
acShellExecute("open","D:\\PROG\\INET\\Palemoon portable\\Palemoon-Portable.exe",
s, nil, 1)
But it is useful only for the requests of single word (without spaces), while the original script handled any requests. I try to replace spaces with %20
s = string.gsub(s, " ", "%20")
but S+ return error message "invalid capture index". What do I do wrong?
Go to Top of Page

Rob

USA
2573 Posts

Posted - 10/05/2015 :  20:47:13  Show Profile  Visit Rob's Homepage  Reply with Quote
See this URL:

http://stackoverflow.com/questions/11008520/putting-in-string-gsub-in-lua

It looks like you simply need to use "%%20" instead of "%20", as % needs to be escaped.
Go to Top of Page

Alex22

Ukraine
19 Posts

Posted - 10/06/2015 :  14:32:27  Show Profile  Reply with Quote
Thank you, now it works OK!
Go to Top of Page

Alex22

Ukraine
19 Posts

Posted - 10/15/2015 :  13:31:07  Show Profile  Reply with Quote
New question. Now I want to search the accurate phrase (like text in quotes). How can I input quotes to script's code?
Go to Top of Page

Rob

USA
2573 Posts

Posted - 10/16/2015 :  00:20:03  Show Profile  Visit Rob's Homepage  Reply with Quote
Try something like this, %22 is the URL encoded value for a quotation mark:
acSendKeys("{DELAY=50}^c")
acDelay(50)
local s = acGetClipboardText()
s = string.gsub(s, " ", "%20")
s = "http://yandex.ua/yandsearch?rdrnd=312365&text=%22"..s.."%22"
acShellExecute("open","D:\\PROG\\INET\\Palemoon portable\\Palemoon-Portable.exe", s, nil, 1)
Go to Top of Page

Alex22

Ukraine
19 Posts

Posted - 10/16/2015 :  07:24:27  Show Profile  Reply with Quote
As always thank you very much.
Go to Top of Page

control_freak

51 Posts

Posted - 04/16/2016 :  16:13:22  Show Profile  Reply with Quote
how do i get the link of any websites internal search engine? like if i want to search the selected text in imdb.com or dailysubs.com :|?
Go to Top of Page

Rob

USA
2573 Posts

Posted - 04/16/2016 :  16:21:41  Show Profile  Visit Rob's Homepage  Reply with Quote
That's pretty much near impossible. Every website is different and can be changed at any time without notice. You'd have to dig into the HTML of each one and figure it out, unless there's an API or something that they expose to be accessed via URL.
Go to Top of Page

control_freak

51 Posts

Posted - 04/16/2016 :  16:51:47  Show Profile  Reply with Quote
have u used fasterchrome? it had some option like u can search on wiki or imdb for selected text. i want to make gestures to search for the subtitle of that file or something like that.
Go to Top of Page

Rob

USA
2573 Posts

Posted - 04/16/2016 :  17:02:42  Show Profile  Visit Rob's Homepage  Reply with Quote
Then you'll have to do some work to figure out the URL formats and build the strings. There's no existing code I have or that I've seen anyone else post. Do some Google searches and see if you can find the URLs for other engines, then you should be able to build out your scripts!
Go to Top of Page

control_freak

51 Posts

Posted - 04/16/2016 :  17:10:42  Show Profile  Reply with Quote
oh okay thank you rob. and what if i want to add ":srt" after every keyword while searching on google
Go to Top of Page

chandisciple

75 Posts

Posted - 04/18/2016 :  02:21:56  Show Profile  Reply with Quote
try adding,

..::srt..
Go to Top of Page

control_freak

51 Posts

Posted - 04/21/2016 :  15:29:01  Show Profile  Reply with Quote
acSendKeys("{DELAY=50}^c")
acDelay(50)
local s = acGetClipboardText()
s = 'https://www.google.com/search?hl=en&newwindow=1&output=search&q=' .. s
acShellExecute("open","rundll32.exe", "url.dll,FileProtocolHandler "..s, nil, 1)

where should i put ..:srt..?
Go to Top of Page

leo_ng

3 Posts

Posted - 04/30/2016 :  12:18:39  Show Profile  Reply with Quote
quote:
Originally posted by control_freak

acSendKeys("{DELAY=50}^c")
acDelay(50)
local s = acGetClipboardText()
s = 'https://www.google.com/search?hl=en&newwindow=1&output=search&q=' .. s
acShellExecute("open","rundll32.exe", "url.dll,FileProtocolHandler "..s, nil, 1)

where should i put ..:srt..?




Any idea? Pls help~ If i use this function in Chinese will be garbled ~.~
Unless add utf-8 at last~~~~
Go to Top of Page

Rob

USA
2573 Posts

Posted - 04/30/2016 :  12:22:50  Show Profile  Visit Rob's Homepage  Reply with Quote
The new version of S+ I'm writing is fully unicode compliant. There's unfortunately nothing you can do to support unicode in the current S+ :/
Go to Top of Page

leo_ng

3 Posts

Posted - 05/02/2016 :  07:44:19  Show Profile  Reply with Quote
quote:
Originally posted by Rob

The new version of S+ I'm writing is fully unicode compliant. There's unfortunately nothing you can do to support unicode in the current S+ :/



thz Rob~^^ Looking forward to your new version.
Go to Top of Page

control_freak

51 Posts

Posted - 05/03/2016 :  12:21:50  Show Profile  Reply with Quote
when is the new version is coming :|
Go to Top of Page

Rob

USA
2573 Posts

Posted - 05/03/2016 :  16:57:37  Show Profile  Visit Rob's Homepage  Reply with Quote
Sorry, but it's probably going to be a few months at least. It's a LOT of work!
Go to Top of Page

control_freak

51 Posts

Posted - 05/22/2016 :  02:26:57  Show Profile  Reply with Quote
figured out how to search selected text on imdb.com. it opens search result of imdb if texts are selected and if no text is selected the gesture opens imdb.com

acDelay(100)

local a1 = acGetClipboardText()
acSendKeys("{DELAY=50}^c")
acDelay(50)
local a2 = acGetClipboardText()
if a2 ~= a1 then
a2 = 'http://www.imdb.com/find?ref_=nv_sr_fn&q='..a2 -- You can search in any web. Just need to see the address bar in the page you want to search, like youtube.
acShellExecute("open","rundll32.exe",
"url.dll,FileProtocolHandler "..a2, nil, 1)
else
wEb = 'www.imdb.com/'--change the web here!
acShellExecute("open","rundll32.exe",
"url.dll,FileProtocolHandler "..wEb, nil, 1)

end

Edited by - control_freak on 05/22/2016 02:30:01
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000