Dedicated to my friend @Y4m1n for her 24th birthday.
An Alfred workflow to do daily searches(text, image and open urls in text) with one hotkey.
- Download Search Selection.alfredworkflow
- Double click
Search Selection.alfredworkflow
to install. - Click
Import
Button. - Double click
Hotkey
and set your shortcut.(I'm using alt + s).
alt+s
- Open url(s):
Select this line and press hotkey, it will open willbc.cn and https://news.ycombinator.com/ in the browser.
- Text Search:
- Image Search: Select a local image or browse in Alfred File Search and press hotkey, please wait for seconds.
Default: Google
- Search
test
with your favorite search engine. - Get the url from the results, e.g.
https://duckduckgo.com/?q=
- Open Alfred Preferences -> Workflows -> Search Selection
- Right click
Open in Editor
workflow -> Open in Finder - Open
script.rb
, press Command + F to find text. - Replace
https://google.com/search?q=
with your favorite search engine url.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
The code logic is very simple:
if File.exist?(filepath)
if File.image?(filepath)
search_image(filepath)
else
push_notification('Please select an image', 'Supports jpg, gif, png, bmp, tif, or webp')
end
elsif extract_urls(query).any?
open_urls(query)
else
search_text(query)
end
- Images are uploaded to https://sm.ms/
- Image search was inspired by https://github.com/BlackwinMin/alfred-gallery/tree/master/img%20Search
- It was built with RubyMine which helped me improve the code quality a lot.
- Icons made by https://www.flaticon.com/authors/roundicons
I tried write it with Python, it was not simple at all, I had to deal with some package/language issues. Pain!
I tried write it with Shell, all I did was trying to figure out the syntax. Deep Pain!
I tried write it with Go, well I never get started. Lost...
I tried Ruby(with little Shell code inside), it just worked without much pain! 💖 I really enjoyed it!