StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
 All Forums
 Lua Scripts
 General Action Scripts
 Search Google for Selected Text

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

UserName:
Password:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkInsert EmailInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Rob 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)
9   L A T E S T    R E P L I E S    (Newest First)
Marcel 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

Marcel 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.
Hax 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.
Rob 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 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?
breakcore 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.
Rob 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 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?
Hax 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.

StrokesPlus Forum © 2011-2012 Rob Larkin Go To Top Of Page
Snitz Forums 2000