-
-
Notifications
You must be signed in to change notification settings - Fork 846
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I press the shortcut key and use Google to search for the selected content? #2535
Comments
You will have to use a script for that and call it from
To use this, put two events in Or use Hammerspoon (or QuickSilver, Alfred, BetterTouchTool, etc.). If you want a lot of customization, or already use one, this will be the better option. To do this without any script, the hardest part is opening browser and inputting selected text (or google search link). The problem is that depending on CPU usage, time taken for opening browser will vary, but we can only mention a fixed time in KE. A 3-5 seconds delay is close enough, but even that maybe slow. If you want to give it a try, this can be done using multiple
|
@MuhammedZakir {
"from": {
"modifiers": {
"optional": [
"any"
]
},
"simultaneous": [{
"key_code": "i"
},
{
"key_code": "o"
}
]
},
"to": [{
"key_code": "c",
"modifiers": [
"left_command"
]
}],
"to_delayed_action": {
"to_if_invoked": [{
"shell_command": "open https://www.google.com/search?q=$(pbpaste)"
}]
},
"parameters": {
"basic.to_delayed_action_delay_milliseconds": 100
},
"type": "basic"
} |
Nice! :-) I guess I made it more complicated. A suggestion: I would also use another "pboard" to save current clipboard content and then after opening link, copy the saved content back to main clipboard. See pqrs-org/KE-complex_modifications#697 (comment):
|
It only works for English characters, not for words containing special characters such as å or Chineses characters. Don't know if there is a solution on it. Thanks |
I think you will have to encode the text before using them in the URL. Haven't tried it though. E.g. using NodeJS "shell_command": "open \"https://www.google.com/search?q=$(node -p \"encodeURIComponent($(pbpaste))\")\"" |
@yu-soong |
@MuhammedZakir, Using NodeJS doesn't work neither. It only opens google but no word is pasted into the search bar. |
@yu-soong |
@yu-soong "parameters": {
"basic.to_delayed_action_delay_milliseconds": 300
}, |
@GanZhiXiong |
|
@GanZhiXiong |
那你直接在终端执行如下命令呢? $ open 'https://www.google.com/search?q=abc123你好' |
@GanZhiXiong |
@yu-soong 估计是你系统或 shell 的问题吧? |
@GanZhiXiong |
@yu-soong ganzhixiong@ganzhixiongdeMacBook-Pro-2 ~ % open 'https://www.google.com/search?q=abc123你好'
The file /Users/ganzhixiong/https:/www.google.com/search?q=abc123你好 does not exist. 通过参考这篇文章 https://developer.apple.com/forums/thread/663762 ,我找到了解决方法:对剪贴板内容进行 URL 编码即可。 open "https://www.google.com/search?q=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "abc123你好")" |
@GanZhiXiong |
@yu-soong |
@GanZhiXiong 用以下的还是中文用不了,显示的是问号。英语的可以。是不是我写的有问题? |
open "https://www.google.com/search?q=$(python -c "import urllib, sys; print urllib.quote(sys.argv[1])" "$(pbpaste )")" |
@GanZhiXiong |
@yu-soong |
@GanZhiXiong |
@yu-soong {
"from": {
"modifiers": {
"optional": [
"any"
]
},
"simultaneous": [{
"key_code": "s"
},
{
"key_code": "d"
}
]
},
"to": [{
"key_code": "c",
"modifiers": [
"left_command"
]
}],
"to_delayed_action": {
"to_if_invoked": [{
"shell_command": "open \"https://www.google.com/search?q=$(python -c \"import urllib, sys; print urllib.quote(sys.argv[1])\" \"$(pbpaste )\")\""
}]
},
"parameters": {
"basi": 300
},
"type": "basic"
} |
@GanZhiXiong |
@yu-soong
|
|
This doesn't work on my M1 Pro (Monterey). |
@GanZhiXiong M1 mac os 11 not work. But run script in command line works well. And I make an issue #3754 for more details. Any suggestions is appreciated! |
@GanZhiXiong fix it by set |
No description provided.
The text was updated successfully, but these errors were encountered: