Author |
Topic |
|
Kingron
39 Posts |
Posted - 03/09/2012 : 03:36:16
|
I wanna using a gesture to run Google search, but the script often make the whole system crashed or S+ crashed. My goal: select some text in any program, draw G gesture, and it auto search the selected text using google
I set gesture as G, the script is
acSendKeys("{DELAY=50}^c") acDebugPrint('====Google Gesture====') local s = acGetClipboardText() acDebugPrint(s) s = 'https://www.google.com/search?hl=en&newwindow=1&output=search&q=' .. s acDebugPrint(s) acShellExecute("open", s, "", "", 1)
|
|
Rob
USA
2615 Posts |
Posted - 03/09/2012 : 07:13:04
|
ShellExecute is really meant for verbs against a file. ShellExecuteEx can technically work (though S+ isn't using it internally), even then there can be issues from what I've read.
I would recommend calling rundll32 instead like below; also notice I've added a small delay after sending CTRL+C to allow time for the text to be copied.
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)
P.S. Very handy action! Going to stick this under the action script forum =)
Edit: I see that it is acceptable to run a URL with ShellExecute, but I've also read about people having problems which is why I suggested the rundll32 option. |
|
|
Rob
USA
2615 Posts |
Posted - 03/09/2012 : 07:28:22
|
Also, is there any consistency to when it crashes? Certain text? Try the script using rundll32 for a while and let me know how it goes.
I've also added a try/catch block around the ShellExecute call, so that may help prevent any errors from bringing down the system. Will be there in 1.7.9. |
|
|
Kingron
39 Posts |
Posted - 03/09/2012 : 08:52:09
|
Even I don't call the shellexecute, it is often crash. The crash is random. When crash, a windows error report dialog shown, and the system is hung.
I guess because the acGetClipboardText might cause this, because I don't add the delay after sent Ctrl + C keys |
|
|
Rob
USA
2615 Posts |
Posted - 03/09/2012 : 08:57:50
|
Are you ever copying a non-English character? Just wondering if it's a Unicode issue. |
|
|
Kingron
39 Posts |
Posted - 03/09/2012 : 09:43:53
|
Doesn't matter the charset.
add the acDelay(80) before Get clipboard text works fine!
I guess the cause for this issue: after sent Ctrl + C, system lock the clipboard and copy the select text, if we don't wait it's finish, and try to get the clipboard text, then S+ can't lock clipboard and return. |
|
|
Rob
USA
2615 Posts |
Posted - 03/09/2012 : 10:10:04
|
That would make sense. |
|
|
Kingron
39 Posts |
Posted - 03/24/2012 : 01:46:07
|
Yesterday, When I run the Google search script in Word 2010, it crashed again.
I had to increase the sleep time to avoid again, but this isn't the final solution.
We prefer to solved this problem thoroughly.
My problem is, when S+ crashed, the whole system performance is terrible until we close the windows error dialog. |
|
|
|
Topic |
|
|
|