Quick Search Results using Raycast and DDGR
This is more or less a proof of concept. I wanted a fast way to look up facts without navigating away from what I’m working on.
Using Raycast is a natural place to start given you can pull it up and make it go away with ease. I looked for extensions in the Raycast Store (they’re free, despite the name) that might help but nothing seemed to do what I wanted. The Wikipedia extension does a great job of pulling information but it’s not as useful if I want a quick fact like “zip code for Portland Maine”.
Next I began looking for command line tools that return web search results. Googler came up as a top choice but the project has been archived. ddgr was the next one I came across; it works beautifully to return DuckDuckGo search results as JSON. I installed it with homebrew ( brew install ddgr ).
Finally, I whipped up a quick Raycast script command that would accept an argument, use ddgr to get the top search results, then spit them out in the Raycast output window. Raycast scrolls to the bottom of the output automatically, so I reversed the order of the top 10 results so that the most relevant appears at the bottom. That’s it!
There isn’t any graceful error handling, automated test coverage, etc. Use it at your own risk. 😉
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#!/usr/bin/env python3 # Required parameters: # @raycast.schemaVersion 1 # @raycast.title DDGR Search # @raycast.mode fullOutput # Optional parameters: # @raycast.icon 🔍 # @raycast.argument1 { "type": "text", "placeholder": "search query", "percentEncoded": false } # Documentation: # @raycast.description Search using the ddgr command line tool # @raycast.author Adam Courtemanche import json import subprocess import sys query = sys.argv[1] output = subprocess.check_output(["ddgr", "--json", query]) data = json.loads(output) # Reverse the results so the most relevant are at the bottom # because Raycast will scroll you to the bottom of the output data.reverse() for result in data: print(f"{result['abstract']} {result['url']}") print("") |