Author |
Topic |
|
Rob
USA
2615 Posts |
Posted - 03/09/2012 : 07:15:40
|
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
|
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. |
|
|
breakcore
Russia
74 Posts |
Posted - 03/11/2012 : 16:06:43
|
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 |
|
|
Rob
USA
2615 Posts |
Posted - 03/11/2012 : 16:33:41
|
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\\... |
|
|
breakcore
Russia
74 Posts |
Posted - 03/12/2012 : 05:35:36
|
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. |
|
|
Hax
128 Posts |
Posted - 05/05/2012 : 08:44:18
|
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? |
|
|
Rob
USA
2615 Posts |
Posted - 05/05/2012 : 19:14:42
|
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. |
|
|
Hax
128 Posts |
Posted - 05/06/2012 : 04:51:24
|
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. |
|
|
Marcel
New Zealand
4 Posts |
Posted - 04/11/2013 : 19:18:51
|
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. |
|
|
Marcel
New Zealand
4 Posts |
Posted - 04/11/2013 : 19:37:56
|
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
|
|
|
Alex22
Ukraine
19 Posts |
Posted - 10/05/2015 : 12:01:23
|
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? |
|
|
Rob
USA
2615 Posts |
|
Alex22
Ukraine
19 Posts |
Posted - 10/06/2015 : 14:32:27
|
Thank you, now it works OK! |
|
|
Alex22
Ukraine
19 Posts |
Posted - 10/15/2015 : 13:31:07
|
New question. Now I want to search the accurate phrase (like text in quotes). How can I input quotes to script's code? |
|
|
Rob
USA
2615 Posts |
Posted - 10/16/2015 : 00:20:03
|
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) |
|
|
Alex22
Ukraine
19 Posts |
Posted - 10/16/2015 : 07:24:27
|
As always thank you very much. |
|
|
control_freak
51 Posts |
Posted - 04/16/2016 : 16:13:22
|
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 :|? |
|
|
Rob
USA
2615 Posts |
Posted - 04/16/2016 : 16:21:41
|
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. |
|
|
control_freak
51 Posts |
Posted - 04/16/2016 : 16:51:47
|
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. |
|
|
Rob
USA
2615 Posts |
Posted - 04/16/2016 : 17:02:42
|
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! |
|
|
control_freak
51 Posts |
Posted - 04/16/2016 : 17:10:42
|
oh okay thank you rob. and what if i want to add ":srt" after every keyword while searching on google
|
|
|
chandisciple
75 Posts |
Posted - 04/18/2016 : 02:21:56
|
try adding,
..::srt.. |
|
|
control_freak
51 Posts |
|
leo_ng
3 Posts |
Posted - 04/30/2016 : 12:18:39
|
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~~~~ |
|
|
Rob
USA
2615 Posts |
Posted - 04/30/2016 : 12:22:50
|
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+ :/ |
|
|
leo_ng
3 Posts |
Posted - 05/02/2016 : 07:44:19
|
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. |
|
|
control_freak
51 Posts |
Posted - 05/03/2016 : 12:21:50
|
when is the new version is coming :|
|
|
|
Rob
USA
2615 Posts |
Posted - 05/03/2016 : 16:57:37
|
Sorry, but it's probably going to be a few months at least. It's a LOT of work! |
|
|
control_freak
51 Posts |
Posted - 05/22/2016 : 02:26:57
|
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 |
|
|
|
Topic |
|